【发布时间】:2016-04-24 11:24:18
【问题描述】:
我在显示通过 JSONP 调用的 JSON 数据时遇到问题。我有一个通过 URL 跨域传递的复杂 JSON 文件,而且我是 JSON 和 ajax 的新手。我在https://learn.jquery.com/ajax/working-with-jsonp/ 关注了一篇 JSONP 文章,这很奏效。现在,在遵循这个问题How do I iterate through this JSON object in jQuery? 之后,我正在尝试遍历 JSON 对象并在 HTML 页面中显示数据,但我不会去任何地方。数据未定义,我不确定自己做错了什么:
// Using LibCal and JSONP
$.ajax({
url: "https://api2.libcal.com/1.0/room_bookings_nickname/?iid=3356&group_id=12306&key=92a47e5c854dee620cca071648c3fc41",
// The name of the callback parameter, as specified by the YQL service
jsonp: "callback",
// Tell jQuery we're expecting JSONP
dataType: "jsonp",
// Tell LibCal what we want and that we want JSON
data: {
q: "select Room name,booked timeslots,booking name from LibCal room bookings",
format: "json"
},
// Work with the response
success: function( response ) {
console.log( response ); // server response
}
});
$.each(data.bookings, function(index, element) {
alert(element.timeslots.room_name);
});
我希望这对我们那里的高级用户来说是一个明显的修复:)
【问题讨论】:
标签: javascript jquery json ajax