Jquery load interval

0

I would like to set a load time between each load() to complete the loading of each. For this I would need to set a stop or something similar inside my Loop. Would that be possible?

 for (var v = 0;v <= 10 ;v++ ){
   //Esperar 3 Segundos e carregar proxima linha
   $("#minhaDiv"+v).load("pagina.php?par="+v);
 }

Thank you!

    
asked by anonymous 11.07.2016 / 15:37

1 answer

0

The delay() method would not work in this case because it only delays the next Jquery chained statement. Something like:

$("#minhaDiv"+v).load("pagina.php?par="+v).delay(3000).toggle("show");

In this case, you can use a trick instead of an ordinary one, it would look something like:

var i = 0;                     //  seta seu indíce pára 0

function myLoop () {           //  vamos criar uma função de loop
   setTimeout(function () {    //  Chama a função a cada 3 segundos
      $("#minhaDiv"+i).load("pagina.php?par="+i); //executa seu load.
      i++;                     //  incrementa o índice
      if (i < 10) {            //  se índice é menor que 10, então continua a o looping
         myLoop();             //  chama a função de looping 
      }                        
   }, 3000)
}

myLoop();

Just adapt according to your requirements.

Based on this response here .

    
11.07.2016 / 15:44