【JS】一个安全稳定的Javascript的Ajax对象生成函数

vb.net

做个记号,兼容IE6~9、火狐、Chrome等主流浏览器

  
    
function getAjax() {
if (window.XMLHttpRequest){
return new XMLHttpRequest();
}
else if (window.ActiveXObject){
var xmldes = [ " MSXML2.XmlHttp " , " Microsoft.XmlHttp " , " MSXML2.XmlHttp.5.0 " , " MSXML2.XmlHttp.4.0 " , " MSXML2.XmlHttp.3.0 " ];
var xmlobj = false ;

for ( var i = 0 ;i < xmldes.length;i ++ ){
try {
xmlobj
= new ActiveXObject(xmldes[i]);
if (xmlobj) return xmlobj;
}
catch (e){}
}

}
return false ;
}

你可能感兴趣的:(JavaScript)