我正在使用jQuery,我有一个aAax请求,如下所示;
$.ajax({
type: 'POST',
url: 'test.php',
data: {
data: "test_data"
},
cache: false,
success: function(result) {
if (result == "true"){
alert("true");
}else{
alert("false");
}
},
});
这样做效果很好。但是,我希望以一种及时的方式,在特定的时间间隔内做到这一点。比方说,我想每30秒执行一次。不应重新加载该页面。我希望这件事发生在后台,隐藏起来。有人知道怎么做吗?
发布于 2011-08-31 18:50:17
setInterval(function() {
$.ajax({
type: 'POST',
url: 'test.php',
data: {
data: "test_data"
},
cache: false,
success: function(result) {
if (result == "true"){
alert("true");
}else{
alert("false");
}
}
});
}, 30000);
发布于 2011-08-31 18:16:20
使用setInterval?http://www.w3schools.com/jsref/met_win_setinterval.asp
或者,如果您只希望它在成功消息之后运行,则可以在成功回调中使用setTimeout来调用发送该ajax请求的函数
https://stackoverflow.com/questions/7255548
复制相似问题