我正在运行一个函数,它每秒钟检查一次远程脚本并更新进度条。我与setInterval
是新的,并且在完成它后停止循环时遇到问题。jQuery setInterval问题
我在几个不同的地方添加了0后期功能和clearInterval(interval);
- 基本上就像遮住了我的眼睛,把尾巴固定在驴子上 - 并没有成功。 data
已达到100,我将在哪里设置clearInterval
停止循环?
function getProgress(hash) {
setInterval(function() {
$.ajax({
type: 'GET',
url: 'http://domain.com/script.php?hash=' + hash,
cache: false,
dataType: 'json',
success: function(data) {
if (data < 100) {
getProgress();
} else {
$('#progress-bar').hide();
}
},
});
}, 1000);
}
请参阅接受的答案:http://stackoverflow.com/questions/109086/stop-setinterval-call-in-javascript – user212514
请发表您如何使用'VAR interval'和'clearInterval' – choz
既然你'使用'setInterval'你的函数将被调用,不需要用'getProgress()'手动调用它' – user3