无法使用 simpleweather.js 读取 null 的 属性 'channel'
cannot read property 'channel' of null with simpleweather.js
我正在使用 simpleweather 插件来显示当前天气并且直到昨天都运行良好。现在它显示错误为“无法读取 属性 'channel' of null”。当我调试脚本时,我发现雅虎数据无法检索说服务不可用因此 query.results.channel 为空。谁能解决我的问题?这是我的代码:
<script type="text/javascript" src="/sites/dev/_catalogs/masterpage/NMSTheme/js/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="/sites/dev/_catalogs/masterpage/NMSTheme/js/jquery.simpleWeather.js"></script>
<script type="text/javascript" src="/sites/dev/_catalogs/masterpage/NMSTheme/js/yqlgeo.js"></script>
<script type="text/javascript">
$(document).ready(function() {
loadWeather();
setInterval(loadWeather, 6000);
});
function loadWeather() {
debugger;
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(function(position) {
var location = (position.coords.latitude + ',' + position.coords.longitude);
var woeid = undefined;
$.simpleWeather({
location: location,
woeid: woeid,
unit: 'f',
success: function (weather) {
var time = ReturnCurrentTime();
placehtml = '<span><h5>' + weather.city + ',' + weather.region + '</h5><span/>';
datehtml = '<span><h5> ' + weather.forecast[0].day + ',' + time + '</h5><span/>';
html = '<span><h5> ' + weather.temp + '°' + ' ' + weather.units.temp + '</h5><span/>' ;
$("#date").html(datehtml);
$("#place").html(placehtml);
$("#weather").html(html);
},
error: function (error) {
$("#weather1").html('<p>' + error + '</p>');
}
});
});
}
}
</script>
Yahoo 似乎已停止提供基于纬度和经度查找位置所需的地理定位服务。不过,使用 simpleWeather 的 woeid 属性 而不是位置仍然有效。
雅虎在 geo.placefinder
查询中引入了一个错误。使用 geo.places
.
将 simpleWeather.js 中的第 26 行替换为:
weatherUrl += 'select * from weather.forecast where woeid in (select woeid from geo.places where text="'+options.location+'" limit 1) and u="'+options.unit+'"';
如果您使用地理位置 lat/long 进行呼叫,请将 options.location 括在括号中:
$.simpleWeather({
location: '(' + lat_long + ')',
在 Github 中查看有关 simpleWeather 问题的更多信息:
https://github.com/monkeecreate/jquery.simpleWeather/issues/174
我正在使用 simpleweather 插件来显示当前天气并且直到昨天都运行良好。现在它显示错误为“无法读取 属性 'channel' of null”。当我调试脚本时,我发现雅虎数据无法检索说服务不可用因此 query.results.channel 为空。谁能解决我的问题?这是我的代码:
<script type="text/javascript" src="/sites/dev/_catalogs/masterpage/NMSTheme/js/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="/sites/dev/_catalogs/masterpage/NMSTheme/js/jquery.simpleWeather.js"></script>
<script type="text/javascript" src="/sites/dev/_catalogs/masterpage/NMSTheme/js/yqlgeo.js"></script>
<script type="text/javascript">
$(document).ready(function() {
loadWeather();
setInterval(loadWeather, 6000);
});
function loadWeather() {
debugger;
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(function(position) {
var location = (position.coords.latitude + ',' + position.coords.longitude);
var woeid = undefined;
$.simpleWeather({
location: location,
woeid: woeid,
unit: 'f',
success: function (weather) {
var time = ReturnCurrentTime();
placehtml = '<span><h5>' + weather.city + ',' + weather.region + '</h5><span/>';
datehtml = '<span><h5> ' + weather.forecast[0].day + ',' + time + '</h5><span/>';
html = '<span><h5> ' + weather.temp + '°' + ' ' + weather.units.temp + '</h5><span/>' ;
$("#date").html(datehtml);
$("#place").html(placehtml);
$("#weather").html(html);
},
error: function (error) {
$("#weather1").html('<p>' + error + '</p>');
}
});
});
}
}
</script>
Yahoo 似乎已停止提供基于纬度和经度查找位置所需的地理定位服务。不过,使用 simpleWeather 的 woeid 属性 而不是位置仍然有效。
雅虎在 geo.placefinder
查询中引入了一个错误。使用 geo.places
.
将 simpleWeather.js 中的第 26 行替换为:
weatherUrl += 'select * from weather.forecast where woeid in (select woeid from geo.places where text="'+options.location+'" limit 1) and u="'+options.unit+'"';
如果您使用地理位置 lat/long 进行呼叫,请将 options.location 括在括号中:
$.simpleWeather({
location: '(' + lat_long + ')',
在 Github 中查看有关 simpleWeather 问题的更多信息:
https://github.com/monkeecreate/jquery.simpleWeather/issues/174