[jQuery] put the value of an xml file in an array
my goal is to put a bunch of SKUs contained in an xml file into an
array, but the value is not being set so that it can be used later in
the jQuery.get.
I have html like this:
<select id="select">
<option val="foobar" selected="selected">Foo Bar</option>
<option val="bar">Bar</option>
<option val="foo">Foo</option>
</select>
I have an xml file constructed like this:
<?xml version="1.0" encoding='ISO-8859-1'?>
<sale>
<item>
<sku>foo123</sku>
<name>Foo Bar</name>
</item>
<item>
<sku>bar123</sku>
<name>Bar</name>
</item>
<item>
<sku>foo321</sku>
<name>Foo</name>
</item>
</sale>
and jquery like this:
var gsText = ""
var laArray = new Array();
$(document).ready(function(){
$("#select option").each(function(i){
var gsText = $(this).text();
jQuery.get("http://www.test.com/xml/test.xml",{},function(xml)
{
// Run the function for each item tag in the XML file
$('item',xml).each(function() {
itemName = $(this).find("name").text();
if(itemName == gsText){
laArray[i] = $(this).find("sku").text();
}
});
});
});
alert(laArray) //this is the line that doesn't work!
});