//创建XMLHttpRequest对象 function createXMLHttpRequest() { try { XMLHttpReq = new ActiveXObject("Msxml2.XMLHTTP");//IE高版本创建XMLHTTP } catch(E) { try { XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP");//IE低版本创建XMLHTTP } catch(E) { XMLHttpReq = new XMLHttpRequest();//兼容非IE浏览器,直接创建XMLHTTP对象 } } } //ajax-post方法 function sendAjaxRequest(url,data,funName) { createXMLHttpRequest(); XMLHttpReq.open("post", url, true); XMLHttpReq.setRequestHeader("Content-type","application/x-www-form-urlencoded"); XMLHttpReq.send(data); XMLHttpReq.onreadystatechange = funName; //指定回调函数 } //回调函数 function customReponse() { if (XMLHttpReq.readyState == 4) { if (XMLHttpReq.status == 200) { var data = XMLHttpReq.responseText; ////回调事件// } } }