Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JQuery SimpleWither问题_Jquery_Weather - Fatal编程技术网

JQuery SimpleWither问题

JQuery SimpleWither问题,jquery,weather,Jquery,Weather,我一直在搞乱这个插件: 我试图在每次满足条件时用JQuery显示文本:如果外面晴朗,则打印“it's sunny”,如果下雪,则打印“it's snowing”等等 我试过: if(weather.tomorrow.code === 32) { $("#weather").html('<h1>It is Sunny!</h1>'); } else if { ... // rest of the possible outpu

我一直在搞乱这个插件:

我试图在每次满足条件时用JQuery显示文本:如果外面晴朗,则打印“it's sunny”,如果下雪,则打印“it's snowing”等等

我试过:

if(weather.tomorrow.code === 32) {
        $("#weather").html('<h1>It is Sunny!</h1>');
    }
    else if {
         ... // rest of the possible outputs. 
if(weather.tomory.code==32){
$(“#weather”).html('天气晴朗!');
}
否则如果{
…//其余可能的输出。
但是什么都不起作用(参见天气代码)。 我在控制台中不断遇到各种错误,比如天气未定义或无法读取代码的属性

以下是我添加的内容:

非常感谢你的帮助。我已经有一段时间没有修复了

谢谢!

请参见,它可以工作:

您必须将代码放入成功部分:

$(document).ready(function () {
    $.simpleWeather({
        zipcode: '',
        woeid: '2357536',
        location: '',
        unit: 'f',

        success: function (weather) {
            html = '<h2>' + weather.tomorrow.high + '&deg;' + weather.units.temp + '</h2>';
            html += '<ul><li>' + weather.city + ', ' + weather.region + '</li>';
            html += '<li class="currently">' + weather.tomorrow.forecast + '</li>';
            html += '<li>' + weather.tomorrow.highAlt + '&deg;C</li></ul>';

            $("#weather").html(html);
/************************** your code HAS TO BE here ************************/
    if(weather.tomorrow.code > 16) {
        $("#weather").html('<h1>Alert: Freezing Rain!</h1>');
    }
    else {
         $("#weather").html('<h1>Alert: Freezing Rain!</h1>');
    }


        },
        error: function (error) {
            $("#weather").html('<p>' + error + '</p>');
        }
    });

/************************** your code was here ************************/

});
$(文档).ready(函数(){
$.SimpleWither({
zipcode:“”,
woeid:'2357536',
位置:“”,
单位:f,
成功:功能(天气){
html=''+weather.moother.high+'°;''+weather.units.temp+'';
html+='
  • '+weather.city+'、'+weather.region+'
  • '; html+='
  • '+weather.moother.forecast+'
  • ; html+='
  • '+weather.moother.highAlt+'°;C
'; $(“#weather”).html(html); /**************************你的代码必须在这里************************/ 如果(weather.tomory.code>16){ $(“#weather”).html('警报:冻雨!'); } 否则{ $(“#weather”).html('警报:冻雨!'); } }, 错误:函数(错误){ $(“#weather”).html(“”+错误+”

”); } }); /**************************你的密码在这里************************/ });
对于“天气未定义”错误

您可以通过check success函数检查ajax是否成功

success: function(weather) { 
    console.log(weather);
},
及 对于“无法读取代码的属性”错误

明天你可以检查天气的价值

success: function(weather) { 
    console.log(weather.tomorrow);
},

您使用的
weather
超出了定义范围。您正在进行AJAX调用(即异步),因此,
weather
仅在成功完成调用时定义,并且仅在
success
处理程序的范围内。在您的代码中,您超出了范围,并且很可能AJAX查询尚未完成。非常感谢!我知道这是一个放置错误,但我就是想不出来。请注意!