【问题标题】:How can I display current weather in plain text thanks to simpleweather.js?借助 simpleweather.js,如何以纯文本形式显示当前天气?
【发布时间】:2015-07-16 16:12:01
【问题描述】:

我正在使用weather.js,我在我的 html 文件中包含了必要的导入:

<script src="js/current.js"></script>
<script src="js/sugar.min.js"></script>
<script src="js/weather.js"></script>
<script type="text/javascript" src="js/converters.js"></script>

并放上html标签来显示天气:

<h2 id="weather"><i></i><span class="conditions"></span></h2>

后来我放了javascript:

 Weather.getCurrent('Kansas City', function(current) {
        $('#weather .conditions').text(Weather.kelvinToFahrenheit(current.temperature()).toFixed() + '° and ' + current.conditions());
 });

(我以this page 为例)。但它不起作用,我看到那边是空的。有没有人给我提示?

一般来说,我的网页上只需要一个简单的字符串,例如:73 度,多云,所以如果有其他我可以使用的 api - 我也会感谢任何提示

【问题讨论】:

  • 请确认您有 jquery 参考。
  • 好的,我有点迷茫 - 我的 javascript 中没有提到参考吗?
  • 不,你必须在你的导入中添加像&lt;script src="//code.jquery.com/jquery-1.11.3.min.js"&gt;&lt;/script&gt; 这样的行。请参阅jquery download page 了解包含 jquery 库的所有选项。
  • 哦,是的,对不起,我完全误解了你的问题,是的,我有当前的 jquery 库..
  • weatherjs文件是哪一个?

标签: javascript jquery html weather


【解决方案1】:

weather.js 使用的http://openweathermap.org/ API 似乎已更改,将不再与此 javascript 库一起使用。如果您在浏览器网络控制台中查看,您可以看到对 openweathermap 的请求返回 512 http 代码响应:

HTTP/1.1 512 OK
Server: nginx/1.6.2
Date: Wed, 06 May 2015 13:55:46 GMT
Content-Type: application/octet-stream
Content-Length: 0
Cache-Control: max-age=60

这是一个服务器错误,而不是在你身边。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-03
    • 2017-01-27
    • 2014-09-01
    • 1970-01-01
    相关资源
    最近更新 更多