我有以下腳本,它似乎只從循環的第一次迭代中獲得的價值,而不是休息:有困難通過JSONP數據循環
$(document).ready(function() {
get_jsonp_feed();
function get_jsonp_feed() {
$.ajax({
url: "http://query.yahooapis.com/v1/public/yql?q=%20SELECT%20*%20FROM%20html%20WHERE%20url%3D%22http%3A%2F%2Fnews.bbc.co.uk%2Fweather%2Fforecast%2F4276%3Fsearch%3Dgerrards%2520cross%26itemsPerPage%3D10%26region%3Dworld%26area%3DGerrards%2520Cross%22%20and%20xpath%20%3D%20'%2F%2Ftable%2Ftbody%2Ftr'&format=json&diagnostics=true&callback=cbfunc",
type: 'GET',
dataType: 'jsonp',
jsonp: 'callback',
jsonpCallback: 'cbfunc',
error: function(xhr, status, error) {
alert(xhr.responseText);
},
success: function(data) {
var itemList = data.query.results.tr[0].td;
for (var i = 0; i < 5; i++) {
alert(itemList[i].div.abbr.content);
}
}
});
}
});
這顯示Mon
後,它顯示Cannot read property 'content' of undefined
。它應顯示5條警報,Mon
,Tue
,Wed
,Thu
和Fri
。
jsfiddle:http://jsfiddle.net/DsEGT/。
謝謝你的指針:VAR itemList中= data.query.results.tr; for(var i = 0; i <5; i ++)//alert (itemList[i].id); (var j = 0; j <5; i ++){ var itemList = data.query.results.tr [i] .td; alert(itemList [j] .div.abbr.content); } } – oshirowanen 2011-06-13 10:13:51