假设我有一些文件:server.php、client.php 和一个表:user[id, name, status]
server.php 将处理诸如:更新用户状态等...
在 client.php 中,我对 server.php 进行了 ajax 调用,以检查状态是否已激活(每 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");
}
});
}
怎么可能做到?
谢谢你的时间!