通过城市名(北京/北京市)获取当前城市当前温度及未来一周天气预报 (Json数据)
$.ajax({
type : "get",
url : "http://wthrcdn.etouch.cn/weather_mini?city=磁县",
data : "json",
success : function(result) {
var obj = jQuery.parseJSON(result)
const current = obj.data.forecast[0]
const type = current.type
const weather = current.low.replace(/[^0-9]/ig,"") + '~' + current.high.replace(/[^0-9]/ig,"") + '℃'
document.getElementById('weather').innerHTML = type + ' ' + weather
}
});
实现结果: