如何在jQuery Ajax调用后更新全局变量(关联数组)?

时间:2016-05-25 10:39:20

标签: javascript jquery ajax

如何在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?

0 个答案:

没有答案