简体   繁体   English

无法识别jquery simpleweather

[英]jquery simpleweather not recognized

I want to show weather on my web site using simpleweatherjs , but it is not working for me. 我想使用simpleweatherjs在我的网站上显示天气,但是它对我不起作用。 Can somebody tell me what I'm doing wrong? 有人可以告诉我我在做什么错吗? Page is blank. 页面为空白。 If I, for example before line $.simpleWeather({...}); 例如,如果我在$ .simpleWeather({...})行之前; put $("#weather").html("test"), then this sentence work, but it is not working under $.simpleWeather({...}); 放$(“#weather”)。html(“ test”),则该语句有效,但在$ .simpleWeather({...})下不起作用。 like it is shown in example. 如示例所示。

Here is my html: 这是我的html:

<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Weather</title>
    <link rel="stylesheet" type="text/css" href="style.css">
    <script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
    <script src="http://cdnjs.cloudflare.com/ajax/libs/jquery.simpleWeather/2.5.0/jquery.simpleWeather.min.js"></script>
</head>
<body>

<div id="weather"></div>
<script>
// Docs at http://simpleweatherjs.com
$(document).ready(function() {
  $.simpleWeather({
    location: 'Austin, TX',
    woeid: '',
    unit: 'f',
    success: function(weather) {
      html = '<h2><i class="icon-'+weather.code+'"></i> '+weather.temp+'&deg;'+weather.units.temp+'</h2>';
      html += '<ul><li>'+weather.city+', '+weather.region+'</li>';
      html += '<li class="currently">'+weather.currently+'</li>';
      html += '<li>'+weather.wind.direction+' '+weather.wind.speed+' '+weather.units.speed+'</li></ul>';

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

</script>
</body>

Are you running the code from a local file? 您是从本地文件运行代码吗? ie navigating to c:\\html\\test.html (or equivalent) in the browser. 即在浏览器中导航到c:\\ html \\ test.html(或等效文件)。

It doesn't appear to work when doing this for me either, however when I hosted the HTML file on a webserver (I used tomcat) and navigated to http://localhost:8080/html/test/html it worked. 对我来说,它似乎也不起作用,但是,当我将HTML文件托管在网络服务器上(我使用tomcat)并导航到http://localhost:8080/html/test/html它起作用了。

Edit: This would explain why it works fine on JS Fiddle as well 编辑:这将解释为什么它也可以在JS小提琴上正常工作

try to clear your line: 尝试清除您的行:

 <link rel="stylesheet" type="text/css" href="style.css">

maybe there is something set hidden in there. 也许那里藏着一些东西。

or/and change the line: (if you are local) 或/并更改行:(如果您是本地人)

//query.yahooapis.com/v1/public/yql

to

  http://query.yahooapis.com/v1/public/yql

Console error says that it is not able to load 控制台错误表明它无法加载

   //query.yahooapis.com/v1/public/yql.....

Hence prefix the url with http or https like 因此,URL带有http或https之类的前缀

    https://query.yahooapis.com/v1/public/yql.....

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

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