小智..
8
有点晚但我使用了jQuery ajax方法.但是如果我没有收到上一次请求的回复,我不想每秒发送一个请求,所以我这样做了.
function request(){
if(response == true){
// This makes it unable to send a new request
// unless you get response from last request
response = false;
var req = $.ajax({
type:"post",
url:"request-handler.php",
data:{data:"Hello World"}
});
req.done(function(){
console.log("Request successful!");
// This makes it able to send new request on the next interval
response = true;
});
}
setTimeout(request(),1000);
}
request();