jQuery获取新浪城市与天气信息

本文介绍了一个使用jQuery发起AJAX请求来获取用户所在城市的天气信息的方法。通过调用新浪提供的API接口,可以实现自动获取并显示当前所在城市的名称及天气状况,包括天气图标和温度范围。
//获取新浪城市与天气信息
function findWeather() {
    var cityUrl = 'http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js';
    $.getScript(cityUrl, function(script, textStatus, jqXHR) {
        var citytq = remote_ip_info.city ;// 获取城市
        $('#provinceCity').html(citytq);
        var url = "http://php.weather.sina.com.cn/iframe/index/w_cl.php?code=js&city=" + citytq + "&day=0&dfc=3";
        $.ajax({
            url : url,
            dataType : "script",
            scriptCharset : "gbk",
            success : function(data) {
                var _w = window.SWther.w[citytq][0];
                var weatherImg = judgingWeather(_w.s1||_w.s2);
                $('#weather').html(_w.s1);
                $('#weatherImg').attr("src","../../../resources/images/manager/"+weatherImg+".png");
                $('#temperature').html(_w.t1 + "℃/" + _w.t2 + "℃  ");
            }
        });
    });
}


<div class="f_r t_i_15 index1_1_2_2">
				<img id="weatherImg" width="50" height="50" class="f_l m_t_8 m_l_20" />
				<div id="weather" class="f_l m_l_12 m_t_8 index1_1_2_font2"></div>
				<div id="temperature" class="f_l index1_1_2_font2"></div>
			</div>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值