I have a below code where I just read a .xml file and try to populate a javascript object. I get the data from the xml and I see it when I print the individual value. But after the whole functino is over somehow I don't see the values in it. The object st_perm_dict is empty again. Why on the last line is it empty again even when it's populated and shows correct values in the .each loop.
start_dx = function () {
var st_perm_dict = {};
url = 'url_to_some_data'
$.get( url, function(xml) {
xmlDoc = $.parseXML ( xml ) ;
$xml = $(xmlDoc)
$(xml).find('item').each ( function() {
var st = $(this).attr('st_data') ;
//console.log ( st ) ; print correctly
st_perm_dict[ st ] = st;
});
});
console.log ( st_perm_dict ) ; // why is this empty . ??
}