0
我正在使用Yahoo Weather API。無法獲取未定義或空引用的屬性「查詢」
這裏是我的代碼:
<script>
var callbackFunction = function (data) {
console.log(data);
var location = data.query.results.channel.location;
var condition = data.query.results.channel.item.condition;
var wind = data.query.results.channel.wind;
var units = data.query.results.channel.units;
document.getElementById('Weather-Info').innerHTML = 'The weather for ' + location.city + ', ' + location.region + ' is ' + condition.temp + units.temperature + ' with a wind speed of ' + wind.speed;
}
callbackFunction()
<script src="https://query.yahooapis.com/v1/public/yql?q=SELECT%20*%20FROM%20weather.forecast%20WHERE%20woeid%3D%222409681%22%20and%20u%3D%22f%22&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=callbackFunction"></script>
每次我進入我收到頁面彈出如下:
無法獲取財產 '查詢'未定義或空引用
但是,如果我點擊否,數據仍然填充..如果它填充數據如果它告訴我一個屬性是不確定的? YQL天氣API非常複雜。
請注意,您在定義之後調用'callbackFunction'。這就是你得到這個錯誤的原因。 – dlopez