原文出处:空空儿http://www.cnblogs.com/doll-net/archive/2007/03/13/673309.html
获取xmlHttp对象的方法很多;以下是我实际使用和网上收集的;
在我实际使用中一般写在一个类中并单独放在一个文件里;使用的时候new一个新对象;避免在同时使用多个时出现错误
1
function xmlHTTP()
2
{
3
var xmlHttp = false;
4
try
5
{
6
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
7
}
8
catch (e)
9
{
10
try
11
{
12
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
13
}
14
catch (e2)
15
{
16
xmlHttp = false;
17
}
18
}
19
if (!xmlHttp && typeof XMLHttpRequest != 'undefined')
20
{
21
xmlHttp = new XMLHttpRequest();
22
}
23
return xmlHttp;
24
}
function xmlHTTP()2
{3
var xmlHttp = false;4
try 5
{6
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");7
} 8
catch (e) 9
{10
try 11
{12
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");13
} 14
catch (e2) 15
{16
xmlHttp = false;17
}18
}19
if (!xmlHttp && typeof XMLHttpRequest != 'undefined')20
{21
xmlHttp = new XMLHttpRequest();22
}23
return xmlHttp;24
}
function xmlHTTP() {
var xmlHTTP;
var msxmlhttp = new Array(
'Msxml2.XMLHTTP.5.0',
'Msxml2.XMLHTTP.4.0',
'Msxml2.XMLHTTP.3.0',
'Msxml2.XMLHTTP',
'Microsoft.XMLHTTP');
for (var i = 0; i < msxmlhttp.length; i++) {
try {
xmlHTTP = new ActiveXObject(msxmlhttp[i]);
} catch (e) {
xmlHTTP = null;
}
}
if(!xmlHTTP && typeof XMLHttpRequest != "undefined")
xmlHTTP = new XMLHttpRequest();
return xmlHTTP;
}


浙公网安备 33010602011771号