AJAX无法定时刷新(解决立即结贴)
jsp文件中有如下两个javascript函数:
function getXHR(){
try {
xhr = new XMLHttpRequest();
} catch (trymicrosoft) {
try {
xhr = new ActiveXObject("Msxml2.XMLHTTP");
} catch (othermicrosoft) {
try {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed) {
xhr = false;
}
}
}
return xhr;
}
function requestData(){
try{
var x=getXHR();
if(x){
//alert("send data!");
x.onreadyStatechange=processMessage;
x.open("GET","messageProcessAction.do");
x.send(null);
window.setTimeout("requestData()",3000);
}
}catch(e){
alert("error3");
}
}
我的意图是让浏览器每三秒向服务器发送一次请求,但测试的结果发现,服务器只收到了一次请求(浏览器也的确每隔三秒做了一些事情,但服务器却只收到一次请求)。请问这是为什么,如何实现每三秒向服务器发送一次请求?