Your code suffers from asynchronousitis. You call the ajax request, but
alert the total before the response can alter the variable. Try doing it
in the success callback as the previous poster suggested and you will
get the correct value:
var total = 0;
function readXML(section) {
$.ajax({
type: "GET",
url : "xmldata/picslist.xml",
dataType: "xml",
success: function(xml){
alert(xml.getElementsByTagName("pic").length); // alerts 4
total = xml.getElementsByTagName("pic").length; // sets total to 4
}
});
alert(total); // alerts 0 - executed as soon as the ajax request is
sent - before the response
};
on 25/08/2009 10:51 ximo wallas said::
I find it really sad that jquery doesn't have a oficial forum out there...
My question is posted in this one, I can't post it here cause the HTML
inside will blow the e-mail:
http://www.jqueryhelp.com/viewtopic.php?t=3616
Can somebody help me with this, I'm really stuck...