jquery 获取客户端ip地址 和 地区位置

搜狐IP地址查询接口(默认GBK):http://pv.sohu.com/cityjson

搜狐IP地址查询接口(可设置编码):http://pv.sohu.com/cityjson?ie=utf-8

使用搜狐接口demo:

<p id="ip"></p>
<script src="../plugins/jQuery/jquery-1.12.4.min.js"></script>
<script src="http://pv.sohu.com/cityjson"></script>
<script type="text/javascript">
    $(function() {
        $('#ip').html(returnCitySN["cip"]);
    })

获取具体的地区位置demo:

 //获取城市ajax
        $.ajax({
            url: 'http://api.map.baidu.com/location/ip?ak=ia6HfFL660Bvh43exmH9LrI6',
            type: 'POST',
            dataType: 'jsonp',
            success:function(data) {
                $('#city').html(data.content.address_detail.province + "," + data.content.address_detail.city)
            }
        });
    })
</script>
</body>
</html>

效果图:

猜你喜欢

转载自blog.csdn.net/weixin_39570075/article/details/81434513