JQuery利用天气API获取天气情况

2016年11月29日18:02:25 发表评论 2,679

该API可以获取某城市的天气情况,包括今天到未来四天和昨天,返回数据为JSON格式,具体情况如图

JQuery利用天气API获取天气情况JQuery利用天气API获取天气情况

代码

[js]
$(".test").html("天气预报请求中。。。");
$.get("http://wthrcdn.etouch.cn/weather_mini?city=济南",function(data){
console.log(data);
var info=data.data;
console.log(info);
console.log(info.forecast[0]);
var today=info.forecast[0];
$(".test").html("天气状况:"+today.type+" 温度:"+today.low+" "+today.high);
},"json");
[/js]

送上一个获取访客城市的API ,大家可自行研究,原理和这个差不多

http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js

注意:本文js使用的的JQuery框架,需要引入
<script type="text/javascript" src="jquery.min.js"></script>
jquery.min.js文件可在网上下载

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: