以下就是创建XMLHttpRequest完整版的代码,希望对大家有用~
function createXMLHttpRequest()
{
if(window.ActiveXObject)
{
try {
xmlHttpRequest = new ActiveXObject("Msxml3.XMLHTTP");
} catch (e) {
try {
xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}}}
}else if(window.XMLHttpRequest)
{
xmlHttpRequest=new XMLHttpRequest();
if (xmlHttpRequest.overrideMimeType)
xmlHttpRequest.overrideMimeType('text/xml');
}
}
本文提供了一个详细的XMLHttpRequest创建方法,通过兼容不同浏览器的方案确保AJAX请求能够顺利进行。无论是在IE还是现代浏览器中,该方法都能成功实例化对象。
448

被折叠的 条评论
为什么被折叠?



