当前位置: 移动技术网 > IT编程>开发语言>Jquery > 检测ip和地区

检测ip和地区

2019年03月24日  | 移动技术网IT编程  | 我要评论

获取当前位置所在省份城市和所用网络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>

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网