【发布时间】:2013-03-13 01:00:57
【问题描述】:
我是 JS/JQuery 的菜鸟。代码如下:
ids = ["1", "2", "3"]
var imageData = [];
for (i=0; i<ids.length; i++) {
$.ajax({
url: 'http://my.images.edu/' + ids[i] + '/info.json',
type: 'GET',
dataType: 'jsonp',
success: function(data) {
imageData.push(data);
}
});
};
// now I want to do stuff with in a loop with the populated
// array, but it's always empty!
console.log(imageData.length);
JSONP 正在工作(我可以在 success 函数中将 JSON 对象响应记录到控制台)。我的猜测based on this question 是当我想使用它时该数组尚未填充,但我可能错了。如果是这样,我该如何解决它,否则,我错过了什么?提前致谢!
【问题讨论】:
标签: javascript jquery ajax jsonp