2
So, I have a loop that will awaken some 10 functions that are AJAX requests, in the functions, which encompasses AJAX requests is a setTimeout()
, what happens is, the loop is done on the hour, and every 10 seconds (as I determined in setTimeout()
) a function is executed..
But, if I want, abort all functions (which have already been called, are only waiting for the time to execute, as I determined in setTimeout
), what I could do?
My code is +- like this:
$("array").each(function(i){
setTimeout(function(){
$.ajax({..});
},5000*i);
});
thanks for the reply and the suggestion, only left a doubt now, will the to pause the
setTimeout
? Regarding the suggestion, I will apply next time what they call Promises and deferred, for me it is still a little confusing, but when I apply maybe uncomplicate once and for all..– Ale
@Alexandrec.Caus can not pause the
setTimeout
. You can have a counter in a variable that is checked by a clocksetInterval
and this check has a flag pause / play. Something like this: https://jsfiddle.net/5ntqc993/– Sergio
perfect @Sergio, liked the example, I’ll end up implementing something like this in my application! hugs and success.
– Ale