why not: var myarray = new Array(); function handleXML(xml) { $(xml).find("something somethingelse").each(function(){ myarray.push( $(this).text()); });
Can't see why that wouldn't work. David http://OntologyOnline.org On Jan 22, 11:53 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > I'm probably being daft, but I'm trying to populate an array by > processing some xml but my (global) array gets destroyed when the ajax > function has done it's job. I know it's because the ajax function. I > know it's a scoping problem but I don't know how to fix it and most > fixes I found online didn't work; > > My code goes something like this: > > var myarray = new Array(); > > function readXml() { > $.ajax({ > type: "POST", > url: story_data_xml_path, > dataType: "xml", > success: handleXml > }); > > } > > function handleXML(xml) { > $(xml).find("something").each(function(i){ > myarray[i] = $(this).find("somethingelse").text(); > }); > > }