zoukankan      html  css  js  c++  java
  • JS框架_(AJAX)检测ip和地区

    百度云盘  传送门   密码:l94p

    实现效果:

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8" />
    <title>获取当前IP地址和省市地区位置代码</title>
    </head>
    
    <script src="js/jquery.min.js"></script>
    
    <style type="text/css">
        .box{text-align: center;}
    </style>
    
    <body>
    
    <div class="box">
        <h1>AJAX检测ip和地区</h1>
        <p id="city"></p>
        <p id="ip"></p>
    </div>
    
    <script type="text/javascript">
    $(function(){
        //获取城市ajax
        $.ajax({
        url: 'http://api.map.baidu.com/location/ip?ak=ia6HfFL660Bvh43exmH9LrI6',  
        type: 'POST',  
        dataType: 'jsonp',
        success:function(data) {  
            console.log(JSON.stringify(data.content.address_detail.province + "," + data.content.address_detail.city));
            $('#city').html(JSON.stringify(data.content.address_detail.province + "," + data.content.address_detail.city))
        }
        });
        //获取ip ajax
        $.ajax({
            url: 'http://freegeoip.net/json/',
            success: function(data){
               console.log(JSON.stringify(data.ip));
               $('#ip').html(JSON.stringify(data.ip))
            },
            type: 'GET',
            dataType: 'JSON'
        });
    })
    
    </script>
    
    </body>
    </html>
    index.html
    <script type="text/javascript">
    $(function(){
        //获取城市ajax
        $.ajax({
        url: 'http://api.map.baidu.com/location/ip?ak=ia6HfFL660Bvh43exmH9LrI6',  
        type: 'POST',  
        dataType: 'jsonp',
        success:function(data) {  
            console.log(JSON.stringify(data.content.address_detail.province + "," + data.content.address_detail.city));
            $('#city').html(JSON.stringify(data.content.address_detail.province + "," + data.content.address_detail.city))
        }
        });
        //获取ip ajax
        $.ajax({
            url: 'http://freegeoip.net/json/',
            success: function(data){
               console.log(JSON.stringify(data.ip));
               $('#ip').html(JSON.stringify(data.ip))
            },
            type: 'GET',
            dataType: 'JSON'
        });
    })
    
    </script>
    (如需转载学习,请标明出处)
  • 相关阅读:
    【Difference Between Primes HDU
    【Pet HDU
    《Java程序设计实验》 软件工程18-1,3 OO实验2
    【数据结构作业】-【带头结点的单链表就地逆置】
    【Miscalculation UVALive
    【Bit String Reordering UVALive
    【Bazinga HDU
    (转载)博弈汇总【巴什博奕,威佐夫博弈,尼姆博弈,斐波那契博弈】
    【Audiophobia UVA
    【Calling Circles UVA
  • 原文地址:https://www.cnblogs.com/1138720556Gary/p/9374511.html
Copyright © 2011-2022 走看看