这是我的代码:
var location = 'RPXX0022'; // Find the code of your location in the following link and change this value between the single quotes: http://edg3.co.uk/snippets/weather-location-codes/
var unit = 'c';
var wq = "SELECT * FROM weather.forecast WHERE location='" + location + "' AND u='" + unit + "'";
var cb = Math.floor((new Date().getTime()) / 1200 / 1000);
var wu = 'http://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent(wq) + '&format=json&_nocache=' + cb;
window['ywcb'] = function(data) {
var info = data.query.results.channel.item.condition;
var city = data.query.results.channel.location.city;
var country = data.query.results.channel.location.country;
$('.ywicon').addClass('wi-yw-' + info['code']);
$('#ywloc').html(city + ", " + country);
$('#ywtem').html(info.temp + '<span>' + '°' + (unit.toUpperCase()) + '</span>');
};
$.ajax({
url: wu,
dataType: 'jsonp',
cache: true,
jsonpCallback: 'ywcb'
});
它给出了这个错误:
未捕获的TypeError:无法读取未定义的属性“condition”
答案 0 :(得分:0)
检查项目对象中是否存在条件
var info = data.query.results.channel.item.condition;
另外在此行中设置调试器并检查您是否在info变量中获取任何值