1 function creatajax(){
2 var ajax=null;
3 if (window.XMLHttpRequest){
4 //对于Mozilla、Netscape、Safari等浏览器,创建XMLHttpRequest对象
5 ajax = new XMLHttpRequest();
6 if (ajax.overrideMimeType){
7 //如果服务器响应的header不是text/xml,可以调用其它方法修改该header
8 ajax.overrideMimeType('text/xml');
9 }
10 } else if (window.ActiveXObject){
11 // 对于Internet Explorer浏览器,创建XMLHttpRequest
12 try{
13 ajax = new ActiveXObject("Msxml2.XMLHTTP");
14 } catch (e){
15 try{
16 ajax = new ActiveXObject("Microsoft.XMLHTTP");
17 } catch (e){}
18 }
19 }
20
21 return ajax;
22 }
23