I'm totally new to jquery but I have a .each loop that fetches some data using ajax and then updates list elements. Right now the .each loop does all list elements at the same time... I need it to do the first one, wait till its done then do the second one etc. etc. I do NOT want to use delay. I want the loop to actually wait until the data is fetched then move on to the next element. Please no faking it using delay. Here is my code simplified.
$(document).ready(function() {
$.ajaxSetup({cache:false});
$('#friendslist li').each(function(index) {
var post_id = $(this).attr("id")
$(this).find(".status div").html("<img src='http://www.url.com/image.jpg'/>");
$(this).find("#replace").load("http://www.url.com/ajaxstuff",{id:post_id});
})
});
Thanks in advance for the help!
setTimeoutorsetInterval; that's not 'faking it', that's the way JavaScript works - there is no threading API available to you so you break up your task into smaller pieces and use one of these functions to do it.