为了得到XMLHttpRequest对象,不同的浏览器对它的支持的方式是不一样的,对于实现dom2的浏览器来说直接new XMLHttpRequest()可,firefox实现了dom2,微软提供了不同的实现;
xmlHttpReq = new XMLHttpRequest();
var msxml = [ "Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0",
"Msxml2.XMLHTTP.3.0", "Msxml2.XMLHTTP",
"Microsoft.XMLHTTP" ];
for ( var i = 0; i < msxml.length; i++) {
try {
xmlHttpReq = new ActiveXObject(msxml[i]);
break;
} catch (e) {
}
}
var xmlhttp = createXMLHttpRequest();
function createXMLHttpRequest() {
var xmlHttpReq = null;
if (window.XMLHttpRequest) {
}
else { // Internet Explorer 6 、8
}
return xmlHttpReq;
}