"The script is a very dumbed down version of what I'm working on"
Before you get into any complicated script, you need to grasp the concept of "Asynchronous" You main mistake is thinking that the loop is going to "wait" when you make the $.ajax call... *it doesn't*... I don't have the time right now to find a good article/blog post to walk you through it, but maybe someone else does On Jun 9, 5:44 pm, psc <petercar...@gmail.com> wrote: > I am very new to javascript/jquery so bare with me. I am using this > loop code below with a populated array called "listarray": > > for(var i in listarray){ > var currententry = listarray[i]; > var finalurl="phpscript.php?entry="+currententry; > jQuery.ajax({ > url: finalurl, > success: function(serverreply){ > alert(currententry); > } > }); > } > > The alerts will always be the exact same: the last item in the array. > So if there are 10 items in the array, it will alert the last one... > 10 times. I'm trying to work with each entry, but I think my code > might be mixed up. > > The script is a very dumbed down version of what I'm working on, but > it's where I'm having my problem. I need to be able to see the ajax > reply, and depending upon what that reply is, do something with the > current array entry. If I alert() the serverreply instead... that > works fine and gives different responses each time... but when I alert > () the "currententry" it's the last item in the array every time. > > However, this only happens inside of the jquery.ajax(). Any > suggestions? Thanks!