执行功能假设我有一些文件:server.php,client.php和一个表:用户[ID,名称,状态]停止在setInterval的
server.php将处理像出头:更新用户状态,等等......
在client.php我有一个AJAX调用server.php为如果状态被激活(以每10秒)检查:
$(document).ready(function(){
setInterval(function(){
check_user_status(user_id)
},10000);
});
check_user_status = function (user_id) {
$.ajax({
type: "post",
data: "user_id="+user_id,
url : "server.php",
success: function(data){
// do something with the response
// I want to exit the checking operation if user is already activated
},
error: function(e){
alert("Error occurred");
}
});
}
怎么能做到呢?
谢谢你的时间!
[clearInterval(https://developer.mozilla.org/en/window.clearInterval)是启动的 – andyb 2012-07-17 10:32:40
可能重复的好去处[如何阻止 “的setInterval”] (http://stackoverflow.com/questions/1831152/how-to-stop-setinterval) – andyb 2012-07-17 10:34:01