I am successfully creating objects from some xml. I am then attempting to put each new object into a a new index of an array which will end up containing all the objects.
However, the array keeps returning as empty. My code follows:
var $locations = [];
/*$obj = {};
$obj['test'] = 'working';
$locations.push($obj);*/
$.ajax({
type: "POST",
url: "/locations/845/data.xml",
dataType: "xml",
success: function($xml){
$($xml).find('node').each(
function(){
$location = {};
//alert( $(this).attr('Latitude') );
$location['latitude'] = $(this).attr('Latitude');
$location['longitude'] = $(this).attr('Longitude');
$location['city'] = $(this).attr('City');
$location['street'] = $(this).attr('Street');
//alert( $location.toSource() );
//alert( $location['latitude'] );
$locations.push($location);
}
);
}
});
alert( $locations.toSource() );
The commented object created and inserted into the $locations array is a test and it works. But the actual useful code within the ajax success function does not.
Can anyone help?
$
in front of JS vars??? – Cipi Sep 3 '11 at 17:13