ajax调用天气接口

$.ajax({
            type: 'GET',
            url: 'https://www.tianqiapi.com/api/?version=v1&city='+ encodeURI("北京", "UTF-8"),
            //data: 'version=v1&city=宣恩',
            dataType: 'JSON',
            error: function () {
                alert('网络错误');
            },
            success: function (res) {
                var t=res.data[0];
                $("#qiwen").text(t.tem.replace("","°"));
                $("#wea").text(t.wea);
                var wea_img=t.wea;
                if(t.wea.lastIndexOf("")!="-1"){
                    wea_img= t.wea.substring(0,t.wea.lastIndexOf(""));
                }
                $("#wea_img").attr("src","image/home/"+wea_img+".png");
                $("#week").text(t.week);
                $("#dayNow").text(t.date);
            },error:function(){

            }
     });

一定要注意上面的encodeURI,你要是不写他的话,你在ie上获取的数据永远是北京的天气,无论你将城市改成什么,然而google就不会出现这种情况

原文地址:https://www.cnblogs.com/dushaojun/p/5235899.html