var city1;
$.ajax({
//獲取客戶端 IP 和 歸屬地
url: "http://chaxun.1616.net/s.php?type=ipoutput=json",
dataType: "jsonp",
success: function (data) {
console.log('ip:' + data.Ip)
console.log('歸屬地:' + data.Isp)
var lcity = data.Isp.split(' ')[0];
//獲取短名稱,如淮安市
city1 = lcity.split('省')[1];
console.log(city1)
//因為是異步刷新,所以兩個請求幾乎同時進行
$.ajax({
type: 'get',
url: 'http://jisutqybmf.market.alicloudapi.com/weather/query',
async: true,
//設置驗證方式,設置請求頭
//1,APPCode
headers: { Authorization: "APPCODE 你的APPCode" },
//2.APPSecret 暫時不能用
//headers: { AppKey: '你的APPKey', AppSecret :'你的APPSecret' },
data: { city: city1 },
success: function (result) {
console.log(result['result'])
//alert(result)
},
error: function () {
alert('error')
}
});
}
});