function get_weather(o) { //跨域获取天气信息
var code = o.val();
$.ajax({
type: "get",
async: false,
cache: false,
url: "get_json.php",
dataType: "jsonp",
data: {
code_city: code
},
jsonpCallback: "weather_callback",
beforeSend: function() {
$(".box").html("<img src='loading.gif' />")
},
success: function(msg) {
var w_str = "";
var img2 = msg.weatherinfo.img2 != 99 ? "-<img src='http://m.weather.com.cn/img/d" + msg.weatherinfo.img2 + ".gif' alt='' title=" + msg.weatherinfo.img_title2 + " />": "";
var img4 = msg.weatherinfo.img4 != 99 ? "-<img src='http://m.weather.com.cn/img/d" + msg.weatherinfo.img4 + ".gif' alt='' title=" + msg.weatherinfo.img_title4 + " />": "";
var img6 = msg.weatherinfo.img6 != 99 ? "-<img src='http://m.weather.com.cn/img/d" + msg.weatherinfo.img6 + ".gif' alt='' title=" + msg.weatherinfo.img_title6 + " />": "";
var temp1 = sort_wd(msg.weatherinfo.temp1);
var temp2 = sort_wd(msg.weatherinfo.temp2);
var temp3 = sort_wd(msg.weatherinfo.temp3);
w_str += "<p>"+ msg.weatherinfo.date_y+ " " + msg.weatherinfo.week+ " " + "所在城市:" + msg.weatherinfo.city + "</p>";
w_str += "<p>今天:" + temp1 + " " + msg.weatherinfo.weather1 + "<img src='http://m.weather.com.cn/img/d" + msg.weatherinfo.img1 + ".gif' alt='' title=" + msg.weatherinfo.img_title1 + " />" + img2 + "</p>";
w_str += "<p>明天:" + temp2 + " " + msg.weatherinfo.weather2 + "<img src='http://m.weather.com.cn/img/d" + msg.weatherinfo.img3 + ".gif' alt='' title=" + msg.weatherinfo.img_title3 + " />" + img4 + "</p>";
w_str += "<p>后天:" + temp3 + " " + msg.weatherinfo.weather3 + "<img src='http://m.weather.com.cn/img/d" + msg.weatherinfo.img5 + ".gif' alt='' title=" + msg.weatherinfo.img_title5 + " />" + img6 + "</p>";
$(".box").html(w_str).addClass("weather_box");
},
error: function() {
$(".box").html('加载失败!');
}
});
}