Range of Jquery loading

Asked

Viewed 219 times

0

I would like to set a charging time between each load() to complete the loading of each. For that I would need to set a stop or something similar inside my Loop. That would 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 !

1 answer

0

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

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

In this case, you can use a trick instead of a common 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 you adapt according to your requirements.

I based myself on that answer here.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.