Home > Web Front-end > JS Tutorial > How to create an ajax object and be compatible with multiple browsers

How to create an ajax object and be compatible with multiple browsers

亚连
Release: 2018-05-25 15:39:23
Original
1729 people have browsed it

This article mainly introduces the simple recording method of creating ajax objects and compatible with multiple browsers. In some cases, it is quite practical. Friends in need can refer to it.

This article mainly introduces How to create an ajax object and be compatible with multiple browsers. Friends who need it can refer to

<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=[&#39;Microsoft.XMLHTTP&#39;, &#39;MSXML.XMLHTTP&#39;, &#39;Msxml2.XMLHTTP.7.0&#39;,&#39;Msxml2.XMLHTTP.6.0&#39;,&#39;Msxml2.XMLHTTP.5.0&#39;, &#39;Msxml2.XMLHTTP.4.0&#39;, &#39;MSXML2.XMLHTTP.3.0&#39;, &#39;MSXML2.XMLHTTP&#39;]; 
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>
Copy after login

. The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

Using Yii integrated pjax (pushstate ajax) to achieve non-refresh loading page

Realizing mobile phone positioning based on h5 ajax

A brief analysis of the use of Ajax in Asp.net MVC

The above is the detailed content of How to create an ajax object and be compatible with multiple browsers. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template