jquery: reading xml document, variable not being passed out of function

criceabbado

New Member
I'm reading a gpx xml document with about 1180 trackpoints, each containing an elevation tag. I can get the length but can't pass it on to use later in an if loop which calculates the total ascent. \[code\]var elevs = [];var $l = 0; $.ajax({ type: "GET", url: "../gpx/27-Mar-13slow.gpx", dataType: "xml", success: function(xml) { $(xml).find('trkseg').each(function(){ $l=$(this).find("trkpt").length; $(xml).find('trkpt').each(function(){ elevs.push(+$(this).find('ele').text()); }); $('#holder').append('<div>' + $l + '</div>'); //fn(); }); } }); \[/code\]ie \[code\]$('#holder').append('<div>' + $l + '</div>');\[/code\] correctly displays the total number of trackpoints, but moving it outside of the function it doesn't. What I assume to be the global variable \[code\]$l\[/code\] won't change to the trackpoint length. Can anyone enlighten me as to why? (The elevs array contains the elevation data ok)
 
Top