Populating an array in the .ajax()
Alright - so I am quite new to Javascript, still thinking somewhat object oriented and most of what I do doesn't work. :-)
I have a script which has an array defined "globally." Then with an .ajax request for an XML file, I use the success function to populate the array. My aim was to then "get" the array data out of the .ajax success function and use it. Unfortunately, all I get is some undefined stuff. What am I doing wrong?
Here is the code (somewhat simplified):
myArray = new Array();
$.ajax({ type: "GET", url: foo, dataType: "xml", success: parseFoo});
function parseFoo(data)
{
$(data).find('xyz').each(function(i)
{
var number = $(this).attr('number');
if (number < someOtherNumber)
{
myArray
[number] = $(this).find('bla').text();
}
});
}
// Now I go out of the function and want to use the populated array:
alert(itemsAlbumArtist[0]);
So the last line basically doesn't work. Anyone know how I can solve this?
Thanks