gpt4 book ai didi

javascript - 当 get() == 'finished' 时停止 jquery setInterval ?

转载 作者:行者123 更新时间:2023-11-28 02:47:54 25 4
gpt4 key购买 nike

有谁知道如果 scan_status.php == 'finished' 是否有办法停止 setInterval?

每 3 秒从 scan_status.php 获取数据 (html)。

我想要的是如果 scan_status.php 完成则停止更新数据。

提前致谢!

瑞恩

 jQuery(function($){
setInterval(function(){
$.get( 'dynamic/page_count.php?u=<?php echo $uid; ?>', function(newRowCount){
$('#pagecounter').html( newRowCount );
});
$.get( 'dynamic/individual_count.php?u=<?php echo $uid; ?>', function(newIndRowCount){
$('#individual_counter').html( newIndRowCount );
});
$.get( 'dynamic/total_word_count.php?u=<?php echo $uid; ?>', function(totalWordCount){
$('#total_word_count').html( totalWordCount );
});
$.get( 'dynamic/scan_status.php?u=<?php echo $uid; ?>', function(scanStatus){
$('#scan_status').html( scanStatus );
});
$.get( 'dynamic/download_status.php?u=<?php echo $uid; ?>', function(downloadStatus){
$('#download_status').html( downloadStatus );
});
},3000); // 5000ms == 5 seconds
});

最佳答案

通过存储调用返回的值来保存对 setInterval 处理程序的引用。

var interval = setInterval(function(){...});

当你想清除它时使用clearInterval(interval);

所以在你的例子中

jQuery(function($){
var interval = setInterval(function(){
$.get( 'dynamic/page_count.php?u=<?php echo $uid; ?>', function(newRowCount){
$('#pagecounter').html( newRowCount );
});
$.get( 'dynamic/individual_count.php?u=<?php echo $uid; ?>', function(newIndRowCount){
$('#individual_counter').html( newIndRowCount );
});
$.get( 'dynamic/total_word_count.php?u=<?php echo $uid; ?>', function(totalWordCount){
$('#total_word_count').html( totalWordCount );
});
$.get( 'dynamic/scan_status.php?u=<?php echo $uid; ?>', function(scanStatus){
$('#scan_status').html( scanStatus );
if (scanStatus == 'finished')
{clearInterval(interval);}
});
$.get( 'dynamic/download_status.php?u=<?php echo $uid; ?>', function(downloadStatus){
$('#download_status').html( downloadStatus );
});
},3000); // 5000ms == 5 seconds
});

关于javascript - 当 get() == 'finished' 时停止 jquery setInterval ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4479985/

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