1 var XMLHttpReq; 2 function createXMLHttpRequest() { 3 if(window.ActiveXObject ) 4 { 5 try { 6 XMLHttpReq = new ActiveXObject("Msxml2.XMLHTTP");//IE高版本创建XMLHTTP 7 } 8 catch(E) { 9 XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP");//IE低版本创建XMLHTTP 10 } 11 } 12 else if(window.XMLHttpRequest) 13 { 14 XMLHttpReq = new XMLHttpRequest();//兼容非IE浏览器,直接创建XMLHTTP对象 15 if( XMLHttpReq .overrideMimeType ) 16 { 17 XMLHttpReq .overrideMimeType( "text/xml" ); 18 } 19 } 20 } 21 22 function sendAjaxRequest(url) { 23 createXMLHttpRequest(); //创建XMLHttpRequest对象 24 XMLHttpReq.open("post", url, true); 25 XMLHttpReq.onreadystatechange = processResponse; //指定响应函数 26 XMLHttpReq.send(null); 27 } 28 29 //回调函数 30 function processResponse() { 31 if (XMLHttpReq.readyState == 4) { 32 if (XMLHttpReq.status == 200) { 33 var text = XMLHttpReq.responseText; 34 } 35 } 36 37 }