0

do you guys have any idea why can't this clear interval? i need this to be clean when ajax complete.

var startTimer = function(){
    setInterval(countdown, 1000);
}

var stopTimer = function(){
    clearInterval(countdown);
}

var countdown = function(){
    console.log('listening');
}

$(document).ajaxComplete(function(event, xhr, settings) {

    if (settings.url.split('?')[1] == undefined)
        stopTimer();
    else
        startTimer();

});
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
Kakajann
  • 124
  • 1
  • 11
  • You need to call `stopInterval()` on the reference returned by `setInterval()` *not* on the function you execute in the interval itself. – Rory McCrossan Oct 17 '18 at 10:54
  • 1
    @Maximilly Moreira Gonçalves — If you want to post an answer, then post an answer. Don't fix the code in the question so the question asks about a problem that doesn't exist in it any more. – Quentin Oct 17 '18 at 14:26

0 Answers0