如何在jQuery Ajax调用后更新全局变量(关联数组)?
var languageCode = {};
$.ajax({
url: 'languages/en.xml',
success: function(xml) {
$(xml).find('string').each(function() {
languageCode[$(this).attr('name')] = $(this).text();
console.log(languageCode.IDSA_HI_THERE); // This works
});
console.log(languageCode);
}
});
console.log(languageCode.IDSA_HI_THERE); // This doesn't work because this gets called before the ajax request. How to make this work?