Populate an array from XML
I'm coming from .NET and new to javascript and jquery and I am having a difficult time with scope. I'm using the following code to populate an array from XML data:
var Point = function(pX, pY)
{
this.x = pX;
this.y = pY;
}
$(document).ready(function(){
var points = new Array();
$.get("ChartData.xml",function(Data){
$(Data).find("Point").each(function() {
var x = $(this).attr("x");
var y = $(this).attr("y");
var pt = new Point(x,y);
points.push(pt);
});
});
for(var j = 0; j < points.length; j++)
{
document.write(points[j].x + " : " + points[j].y);
}
});
When I break at the for loop in firebug the points array is empty but if I break in the jquery each loop I see the the point object being added to the points array. Thanks for your help