<!DOCTYPE html>
<html>
<head>
    <title>ajax</title>

</head>
<body>

    <h1>天气查询</h1>
    <input    type="text" placeholder="请输出你的地址" />

    <button >确定</button>

    <p><span ></span></p>


    <script type="text/javascript" src="jquery-3.1.1.js"></script>
    <script type="text/javascript">
    $(function(){
        $('#ajax').on('click',function(){
            var $telValue=$('#tel').val();
            if($telValue=="") {
                alert('不能为空!');
                return;
            }
            $.ajax({
                type: 'GET',
                dataType:'jsonp',
                jsonp:'callback',                          
                  jsonpCallback:'getName',
                url: 'http://api.asilu.com/weather/',
                data:{
                    "city":$telValue        
                },
                success: function(data){
                    var reslutData=data;
                    console.log(reslutData);    
                    $('#reslut').text("你查询的是:"+reslutData.city+","+"明天的天气是:"+reslutData.weather[0].weather);
                } ,
               

            })
        })
        
    })
    </script>
</body>
</html>

 

相关文章:

  • 2021-10-19
  • 2021-12-15
  • 2022-12-23
  • 2021-09-08
  • 2021-11-17
  • 2021-08-22
  • 2021-04-13
猜你喜欢
  • 2022-01-13
  • 2021-06-02
  • 2022-02-28
  • 2022-12-23
  • 2022-12-23
  • 2021-11-18
  • 2021-10-11
相关资源
相似解决方案