[顶有分]关于XMLHTTP 4.0以下版本的onreadystatechange只触发一次的问题。
cds27 2006-02-20 04:02:53 遇到一个问题在,xmlhttp 4.0以下才会出现的问题。xmlHttp.onreadystatechange只触发一次,之后再也不会出发了,这个问题如何解决?代码如下:
<script language="javascript">
var SERVER="Server.asp";
xmlHttp=new ActiveXObject("Msxml2.xmlHttp.3.0");
//xmlHttp=new ActiveXObject("Microsoft.XMLHttp");//这个版本也不行。
xmlHttp.onreadystatechange=onReady;
get();
function onReady() { //只有第一次触发时执行
if(xmlHttp.readyState==4) {
alert(xmlHttp.responseText)
}
}
function get() {
alert("get");//每次都有执行。
xmlHttp.Open("POST", SERVER, true);
xmlHttp.Send();
timer=setTimeout(get, 3000);
}
</script>