【发布时间】:2016-09-21 18:19:39
【问题描述】:
当页面加载时我想得到一个json:
$.getJSON(_routes['salesInAMonthJS'], { month: "September 2016" }).then(
function(d){
console.log(d);
}
);
这个
$.getJSON(_routes['salesInAMonthJS'], { month: "September 2016" });
还给我
{"9":{"name":"alex lloyd","country":"Germany","antiquity":"new client","amount":"0.0 USD"},"10":{"name"
:"asdasdsadasda dasda","country":"Afghanistan","antiquity":"new client","amount":"0.0 USD"},"11":{"name"
:"Alex Lloyd","country":"American Samoa","antiquity":"new client","amount":"0.0 USD"},"12":{"name":"alex
lloyd","country":"Aruba","antiquity":"new client","amount":"0.0 USD"},"5":{"name":"surgeon bueno","country"
:"Spain","antiquity":"renewal","amount":"2686.97 USD"}}
但是,当用户单击按钮时,我想显示存储在 d 中的数据
例如:
$(document).on("click ", ".tick", function(e) {
e.preventDefault();
$.each(d, function(i, item) {
&("div.container").append(d[i].name);
});
});
但这似乎不起作用,知道我做错了什么吗?谢谢
【问题讨论】:
-
&("div.container")是$("div.container")的拼写错误。 -
你有一个变量范围的问题。
d是$.getJSON回调函数的本地,你不能在另一个函数中访问它。