ajax實現的天氣預報


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

</head>
<body>

    <h1>天氣查詢</h1>
    <input    type="text" placeholder="請輸出你的地址" id="tel"/>

    <button id="ajax">確定</button>

    <p><span id="reslut"></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>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM