檢查下面的代碼互聯網連接...無法取消set.interval
var checkstatus = 0
function checkConnection()
{
$.ajax({
url: "https://path/to/a/file.html",
data: { method: 'checkConnection'},
dataType: "html",
success: function(html)
{
clearInterval(checkstatus);
console.log('connection available');
return;
}
},
error: function(XMLHttpRequest, textStatus, errorThrown){
console.log('retrying');
checkstatus = setInterval(function(){checkConnection()},10000);
}
});
}
爲腳本將繼續每隔10秒檢測線clearInterval(checkstatus);
不起作用,這是爲什麼?
你想要setTimeout而不是setInterval。 –