繁体   English   中英

无法获取未定义或空引用的属性“查询”

[英]Unable to get property 'query' of undefined or null reference

我正在使用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 Weather API非常复杂。

为什么要自己调用回调函数? 无论如何,不​​带参数调用它意味着data将是不确定的,这就是为什么您会收到错误消息。

我对Yahoo一无所知! 天气API,但这似乎是JSONP ,因此请尝试删除此部分:

callbackFunction()

因为脚本加载后会自动调用它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM