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.

    评论

报告相同问题?