我将我的 php 导出为 jsonp,然后调用加载数据的 js 文件。
我只得到最后一个数据对象的输出。我想遍历动作数据并将它们全部输出为<li>data.action</li>格式。如果有人可以帮助弄清楚如何做到这一点,非常感谢。
JSONP
({
"posts": [{
"action": "go to acting school",
"action": "go to a beach",
"action": "go kyacking",
"action": "go skiing in vermont",
"action": "sleep in a cave",
"action": "dress up as favorite celebrity in public",
"action": "see the cherry blossums in Washington DC",
"action": "watch all the rocky movies",
"action": "go sky diving",
"action": "climb Mount Everest",
"action": "climb K2",
"action": "see or participate in war reenactment",
"action": "spend New Years Eve in Times Square",
"action": "jump out of a moving plane",
"action": "jump out of a moving car",
"action": "try eating a new food"
}]
})
查询
$(document).ready(function () {
$.getJSON("http://site.com/lesson.php?count=5&jsoncall=?", function (data) {
$.each(data.posts, function (i, data) {
var jsondata = "<li>" + data.action + "</li>";
$(jsondata).appendTo("ol#results");
});
});
return false;
});