weixin_33701617 2015-08-25 19:36 采纳率: 0%
浏览 47

停止Ajax循环JQuery

I use a ajax code to monitor a folder to count the number of files in that folder that are being copied with a external batch that I didn't have access. I have the following infinite loop that is working quite fine:

function loadProgWav(files){
        $("#wav").load("progress_wav.php?file=<?=$row[2]?>");
    }

    setInterval(function(){ loadProgWav(files) }, 10000);

The ajax return to me a formatted string with a message of how many files have in that folder. But now I need to be able to stop that loop if the progress_wav.php returns false, and show a submit button to redirect to another page of code, but have no idea on how do so.

I'm running the program in a Windows Server 2003 machine with Xaamp.

  • 写回答

1条回答 默认 最新

  • weixin_33697898 2015-08-25 19:39
    关注

    To stop it, first create it like this:

    var interval = setInterval(function(){ loadProgWav(files) }, 10000);

    Later, when you want to stop it, simply do:

    clearInterval(interval);

    This method also applies to setTimeout, just use clearTimeout the same way.

    评论

报告相同问题?

悬赏问题

  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
  • ¥30 乘子法解约束最优化问题的matlab代码文件,最好有matlab代码文件
  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误
  • ¥100 反编译微信小游戏求指导
  • ¥15 docker模式webrtc-streamer 无法播放公网rtsp
  • ¥15 学不会递归,理解不了汉诺塔参数变化
  • ¥15 基于图神经网络的COVID-19药物筛选研究