不同浏览器创建XMLHttpRequest对象

时间:2023-02-12 18:46:54
 function getXHR() {
if (XMLHttpRequest) {
return new XMLHttpRequest();
}
else {
return new ActiveXObject("Microsoft.XMLHTTP");
}
}
 function getXHR() {
if (typeof XMLHttpRequest == "undefined") {
XMLHttpRequest = function() {
try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); } catch (e) { }
try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); } catch (e) { }
try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { }
return false;
}
}
return new XMLHttpRequest();
}