* 定位當前城市
*/
function locationInit(){
$.getScript('http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js', function(_result) {
if (remote_ip_info.ret == '1') {
cityName = remote_ip_info.province;
// console.log(cityName)
$("#cityName").html(cityName);
}
});
}
/**
* 根據城市獲得天氣
*/
function cityWeatherInit(){
//跨域是瀏覽器的安全策略.
//jQuery 解決的方式.
var relName = $("#cityName").html();
var todayimg = '';
var tomorrowimg = '';
$.ajax({
url:"http://api.map.baidu.com/telematics/v3/weather",
type:"get",
data:{
location:relName,
output:'json',
ak:'祕鑰'
},
/*預期服務器端返回的數據類型,假設我現在跨域了,我就改成jsonp 就可以了 */
dataType:"jsonp",
success:function(data){
var weatherData=data.results[0].weather_data;
console.log(weatherData)
}
}
})
}