【发布时间】:2016-08-10 02:59:10
【问题描述】:
我正在尝试使用 ajax 请求构建一个 JSON 对象,然后打印出所有经过美化的数据,以便于阅读。
这是我所拥有的:
var url, data;
var shows = ["stranger things", "the night of"];
var json = {};
$.each(shows, function(i, show) {
url = 'https://www.omdbapi.com/?t=' + show + '&type=series&plot=short'
$.ajax(url, {
complete: function(obj, status){
data = $.parseJSON(obj.responseText);
json.push(obj.responseText);
console.log(data);
}
});
});
var jsonPretty = JSON.stringify({shows: json}, null, '\t');
$("pre").text(jsonPretty);
https://jsfiddle.net/we1p7cqj/1/
问题出在json.push(obj.responseText) 附近,但我无法找到解决办法。
有什么想法吗?
【问题讨论】: