我现在有一个让我困惑的问题。我使用ajax从网站获取一些ID。一旦完成,我想将ID存储在一个变量中作进一步处理。我有我的代码布局是这样的:等待AJAX请求完成?
var ids;
function get_ids() { ... Get the ID's from the site and store them in the global variable ids ... }
get_ids();
alert(ids.length);
正如你可以看到IDS将始终为0,因为该脚本将继续运行在get_ids Ajax请求有机会作出回应前。
什么是我想要做的最好的方法?我想等到get_ids完成。
链接似乎已关闭 – 2016-02-25 19:44:48