检测ip和地区

获取当前位置所在省份城市和所用网络IP

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>检测ip和地区</title>
</head>

<body>
    <div class="box" style="text-align: center;">
        <h1>您当前所在ip和地区</h1>
        <p id="city"></p>
        <p id="ip"></p>
    </div>

    <script src="https://cdn.bootcss.com/jquery/1.9.1/jquery.min.js"></script>
    <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));
                $('#city').html(JSON.stringify(data.content.address_detail.province + "," + data.content.address_detail.city))
            }
            });
            //获取ip ajax
            $.ajax({
                url: 'http://ip-api.com/json',
                success: function(data){
                   console.log(JSON.stringify(data));
                   $('#ip').html(JSON.stringify(data.query))
                },
                type: 'GET',
                dataType: 'JSON'
            });
        })

    </script>
</body>
</html>
原文地址:https://www.cnblogs.com/wrongcode/p/10584472.html