0

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 . ?? 
}
  • Please provide code on how to do it. ( Don't mark it as duplicate ) – user3179387 Nov 06 '14 at 22:35
  • You have to move `console.log(...)` into the function you pass to `$.get`. It has to come immediately after `st_perm_dict[ st ] = st;` and before `})`. – meetamit Nov 07 '14 at 07:45

0 Answers0