JavaScript天气接口

闲话少叙上代码

  1. function getWeather(city) {
  2. var weatherObj = {}
  3. var url = "http://wthrcdn.etouch.cn/weather_mini?city=" + city;
  4. $.ajax({
  5. async: false,
  6. type: "GET",
  7. url: url,
  8. success: function (res) {
  9. weatherObj = JSON.parse(res);
  10. },
  11. error: function (error) {
  12. console.log("获取天气数据失败请联系管理员");
  13. }
  14. });
  15. if (weatherObj.data) return weatherObj.data;
  16. else return null;
  17. }

地址:http://wthrcdn.etouch.cn/weather_mini
image.png