執行功能假設我有一些文件: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