zoukankan      html  css  js  c++  java
  • 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就不会出现这种情况

  • 相关阅读:
    关于XML文档
    Why sql is called structured query language?1
    UML学习---交互
    C#为什么不采用多继承:
    url中
    array
    hard
    构造函数返回值
    布局容器layout Container
    k8s的概念
  • 原文地址:https://www.cnblogs.com/dushaojun/p/5235899.html
Copyright © 2011-2022 走看看