如何创建ajax对象并兼容多个浏览器
- 作者: 哇偶丶Sugar
- 来源: 51数据库
- 2021-09-04
这篇文章主要介绍了如何创建ajax对象并兼容多个浏览器,需要的朋友可以参考下
<script>
function createajax(){
var request=false;
//window对象中有xmlhttprequest存在就是非ie,包括(ie7以上版本)
if(window.xmlhttprequest){
request=new xmlhttprequest();
if(request.overridemimetype){
request.overridemimetype("text/xml");
}
//window对象中有activexobject属性存在就是ie
}else if(window.activexobject){
var versions=['microsoft.xmlhttp', 'msxml.xmlhttp', 'msxml2.xmlhttp.7.0','msxml2.xmlhttp.6.0','msxml2.xmlhttp.5.0', 'msxml2.xmlhttp.4.0', 'msxml2.xmlhttp.3.0', 'msxml2.xmlhttp'];
for(var i=0; i<versions.length; i++){
try{
request=new activexobject(versions[i]);
if(request){
return request;
}
}catch(e){
request=false;
}
}
}
return request;
}
var ajax=createajax();
alert(ajax);
</script>
推荐阅读
