ajax检测ip和地区通过百度地图

    //获取城市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 src='http://libs.baidu.com/jquery/1.10.2/jquery.min.js'></script>

demo链接:http://www.jq22.com/demo/jqueryIp201806181614/

posted @ 2018-06-25 17:00  李晓梦  阅读(209)  评论(0编辑  收藏  举报