Reputation: 1365
Actually My Script is
var i=0;
while(i < folder.length)
{
$("#hide_message").load('/fdc.php?path='+encodeURIComponent(folder[i]) );
//Delay After 10 Sec
$("#hide_message").load('/member.php?path='+encodeURIComponent(folder[i]) );
//Delay After 10 Sec
i++;
}
Is this possible to make delay every line in jquery.
Upvotes: 1
Views: 124
Reputation: 370
Please go through the following questions(and it's answers), here in stackoverflow.
Upvotes: 4
Reputation: 29285
You may want to do something like this:
var i = 0;
while(i < folder.length) {
var index = i;
setTimeout(function() {
$("#hide_message").load('/fdc.php?path=' + encodeURIComponent(folder[index]));
}, i * 1000);
setTimeout(function(){
$("#hide_message").load('/member.php?path=' + encodeURIComponent(folder[index]));
}, (i + 1) * 1000);
i++;
}
Using this way none of those AJAX loadings coincide.
Note: You shouldn't pass i
as an index to folder
array. You should instead declare a local variable and pass it. var index = i;
. The why would be some side effects of JavaScript closure.
Upvotes: 1
Reputation: 1887
Of course that is possible.
Take a look into the jquery API document.
var i=0;
while(i < folder.length)
{
$("#hide_message").load('/fdc.php?path='+encodeURIComponent(folder[i]) );
//Delay After 10 Sec
$("#hide_message").delay(1000).load('/member.php?path='+encodeURIComponent(folder[i]) );
//Delay After 10 Sec
i++;
}
You can try this. But I didn't test it!
The .delay() method is best for delaying between queued jQuery effects. Because it is limited—it doesn't, for example, offer a way to cancel the delay—.delay() is not a replacement for JavaScript's native setTimeout function, which may be more appropriate for certain use cases.
Upvotes: 1