【发布时间】:2013-02-05 13:32:50
【问题描述】:
我是 JavaScript 和 jquery 的新手...我一直在尝试编写一段简单的代码来使用天气 api 来提醒当前温度。
这是我目前得到的:
<script src="http://code.jquery.com/jquery-1.9.1.js"/>
<script>
var my_city="Washington,USA";
var my_key="8b0642a6c7133932132002";
var no_of_days=2;
// build URI:
var uri="http://free.worldweatheronline.com/feed/weather.ashx? q="+my_city+"&key="+my_key+"&format=json&no_of_days="+no_of_days+"&includeLocation=yes";
// uri-encode it to prevent errors :
uri=encodeURI(uri);
jQuery.get(uri,function(r){
current_temp_C =r.data.current_condition[0].temp_C;
alert(current_temp_C);
},"json");
</script>
但是,没有显示任何内容。如果有人能指出我哪里出错了,请告诉我! 谢谢!
【问题讨论】:
-
还有其他天气资源有演示代码codepen.io/jamesfleeting/pen/wHism
-
很棒的演示 Shanimal,但我更多的是针对当前温度的文本。谢谢!
-
这是另一个codepen.io/anon/pen/bvyDh的示例
-
哈哈,正是我要找的东西:)