I have setInterval
with an interval of 2 seconds.
I need to stop this interval at a certain point and start it again with a new time.
Scope
I make an AJAX inside the setInterval. As soon as the AJAX response is success (for example), it repeats the interval again. If it is an error, it stops the interval, changes the interval time, and restarts it again.
I've been able to do the following so far:
var TempoRequest = 2200;
var Ativo = true;
if(Ativo === true){
VerificaChat = setInterval( function(){
if(acao){
//repete o intervalo dnv
}else{
var Ativo = false;
var TempoRequest = 15000;
clearInterval(VerificaChat);
}
}, TempoRequest );
}