我有這樣的代碼:中止通話中「完整:」回調
$(function() {
(function poll(){
var update_progress = setTimeout(function(){
var jxhr = $.ajax({
type: "POST",
url: "grab.php",
data: "test",
success: function(data){
var error = data.error;
if(error == false) {
// My nonsense is here
} else if(error == true) {
// Stop sending AJAX request
clearTimeout(update_progress);
jxhr.abort();
}
}, dataType: "json", complete: poll, timeout: 2000 });
}, 2000);
})()
});
正如你可以看到我試着中止調用「完整:」再一次,如果我的腳本返回一個錯誤回調,而且我清楚超時。
基本上它不應該做任何ajax請求了。但它仍然如此。我錯了什麼?
您無法中止已完成的請求。在這裏除了擁有一個全球性的國旗,你在成功上設置了錯誤,然後在錯誤的情況下完全放棄。 –
這只是邏輯^^我只是想停止進一步的請求。 – Michael
沒錯,但這就是邏輯。你必須取消使用某種標誌。 –