我的ajax功能每15秒工作一次.我想在2分钟后停止它.
我怎样才能做到这一点?
window.setInterval(function () { var request = $.ajax({ ... }) }, 15000);
void.. 5
使用时clearInterval
,该clearInterval()
方法清除使用该方法设置的计时器setInterval()
.
var request;
var _timer = setInterval(function() {
request = $.ajax({
...
});
}, 15 * 1000);
setTimeout(function() {
clearInterval(_timer);
request.abort(); // If you want to abort the xhr which are still executing after 2 minutes
}, 2 * 60 * 1000);
使用时clearInterval
,该clearInterval()
方法清除使用该方法设置的计时器setInterval()
.
var request;
var _timer = setInterval(function() {
request = $.ajax({
...
});
}, 15 * 1000);
setTimeout(function() {
clearInterval(_timer);
request.abort(); // If you want to abort the xhr which are still executing after 2 minutes
}, 2 * 60 * 1000);