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::