给onreadystatechange赋了程序了就不要在别的地方调用hsc了,因为那样responseText会出错。
程序代码:
<script> onload=function(){cxhr();setInterval("cxhr()",2000);} function XMLHttps(){ var ret=null; try {ret=new ActiveXObject("Msxml2.XMLHTTP")} catch(e){try {ret=new ActiveXObject("Microsoft.XMLHTTP")}catch(ee){ret=null;}} if(!ret&&typeof XMLHttpRequest !="undefined"){ret=new XMLHttpRequest();} return ret; } function cxhr(){ var xmlHttp=XMLHttps(); xmlHttp.open("GET","onlineserver.asp",false); xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); xmlHttp.onreadystatechange=function(){ if(xmlHttp.readyState==4 && xmlHttp.status==404){alert("读取页面失败");return false;} if(xmlHttp.readyState==4 && xmlHttp.status==500){alert("程序执行错误");return false;} if(xmlHttp.readyState==4 && xmlHttp.status==200){book.innerHTML=xmlHttp.responseText;}} xmlHttp.send(null); } </script>