function createxhr() { if (window.xmlhttprequest) { return new xmlhttprequest(); } if (window.activexobject) { var msxmls = ['msxml3', 'msxml2', 'microsoft'] for (var i=0; i < msxmls.length; i++) { try { return new activexobject(msxmls[i]+'.xmlhttp') } catch (e) { } } throw new error("no xml component installed!") } } function dopage(obj,url) { var xmlhttp = createxhr(); var xmlhttpurl = url; xmlhttp.open("get", xmlhttpurl, true); xmlhttp.send(null); xmlhttp.onreadystatechange = function () { if (xmlhttp.readystate == 4) { if (xmlhttp.status == 200) { document.getelementbyid(obj).innerhtml=xmlhttp.responsetext; } } } } /** *功能:初始化一个xmlhttp对象 */ function initajax() { var ajax = false; try { ajax = new activexobject("msxml2.xmlhttp"); } catch (e) { try { ajax = new activexobject("microsoft.xmlhttp"); } catch (e) { ajax = false; } } //如果一个类型的变量没有定义的话,运用typeof它就将返回undefined //如果一个类型的变量定义了的话,它就将返回这个变量的类型. if(!ajax && typeof xmlhttprequest != 'undefined') { ajax = new xmlhttprequest(); } return ajax; }