这篇文章主要介绍了如何创建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>
上面是我整理给大家的,希望今后会对大家有帮助。
相关文章:
使用yii整合的pjax(pushstate+ajax)实现无刷新加载页面
基于h5 ajax实现手机定位
浅析asp.net mvc 中ajax的使用
以上就是如何创建ajax对象并兼容多个浏览器的详细内容。
