1.引入jquery和cityjson

<script src="https://pv.sohu.com/cityjson?ie=utf-8" type="text/javascript"></script>

2.ajax请求

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。
getWeather();
function getWeather() {
  jQuery.support.cors = true;
  $.ajax({
    url: "http://wthrcdn.etouch.cn/weather_mini",
    type: "GET",
    dataType: 'json',
    data: {city: (returnCitySN.cname).split('省')[1]}, //(returnCitySN.cname).split('省')[1]:获取所在的市
success:
function (res) { //var res=JSON.parse(res); var city = res.data.city;//所在城市 var maxTemperature = res.data.forecast[0].high;//最高温度 var minTemperature = res.data.forecast[0].low;//最低温度 var weather = minTemperature.split(' ')[1] + '~' + maxTemperature.split(' ')[1]; var type = res.data.forecast[0].type;//天气状态 }, error: function (err) { console.log(err) } }); }

 

cityjson
扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄