gpt4 book ai didi

javascript - 清除间隔()不工作

转载 作者:行者123 更新时间:2023-12-02 04:30:04 25 4
gpt4 key购买 nike

<script>
var interval_time;

function executeQuery() {
$.ajax({
method: 'GET',
url: "${pageContext.request.contextPath}/get-session-timeout",
success: function(jsonRes, textStatus, jqXmlHttpRequest) {
console.log('success log session out');
console.log(jqXmlHttpRequest.status);
}

});
interval_time = setInterval(executeQuery, 30000);
}

function stopInterval() {
console.log('stop interval hit');
clearInterval(interval_time);
}
</script>
<script>
$(document).ready(function(e) {
console.log('ready');
interval_time = setInterval(executeQuery, 30000);

});
</script>



//FILE UPLOAD AJAX CALL

function uploadJqueryForm() {
//logic
$uploadFrm.ajaxForm({
beforeSend: function() {
interval_time = setInterval(executeQuery, 30000);
//logic
},
success: function(jsonRes) {
stopInterval();
//logic
},
error: function(xhr, textStatus,
errorThrown) {
stopInterval();
//logic
},
complete: function(xhr, extStatus, errorThrown) {
stopInterval();
},
dataType: "text"
}).submit();
}
return false;
}

最佳答案

如果您在已经存在的变量中使用setInterval()而不停止它,您将无法清除它。因此,您应该使用 clearInterval(),然后使用 setInterval()

关于javascript - 清除间隔()不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31582014/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com