PDA

View Full Version : Basic AJAX routine doesn't work in FOR Loop?



adrian.jfl
07-09-2007, 02:44 PM
Hi,

I'm not very good with javascript/ajax but managed to get this
example working:
http://www.dynamicdrive.com/dynamicindex17/ajaxroutine.htm

I've adjusted the getAjaxRequest function slightly to allow me to
specify where the result goes 'divtoupdate' which is just an
extra argument to the function.

What i'm trying to do is have a button on a page that runs
a loop updating a number of DIVS. It works OK except
only the last DIV in the loop actually gets updated. I think
this has something to do with the example code using
global objects or something.. eg:

for (x in divs_to_update)
{
updatediv = divs_to_update[x];
ajaxpack.getAjaxRequest("example.php?id=" + updatediv, "", processGetPost, "txt", updatediv);
}

Only the last div name (stored on divs_to_update) is
actually updated.. anyone know why?

Can anyone please suggest what I need to change to have each
call in the for loop actually actioned separately?

Thanks a million,
Adrian.