码迷,mamicode.com
首页 > Web开发 > 详细

JS框架_(AJAX)检测ip和地区

时间:2018-07-26 22:07:49      阅读:415      评论:0      收藏:0      [点我收藏+]

标签:jquer   class   body   char   city   htm   open   set   script   

 

 

实现效果:

技术分享图片

 

技术分享图片
<!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>

 

JS框架_(AJAX)检测ip和地区

标签:jquer   class   body   char   city   htm   open   set   script   

原文地址:https://www.cnblogs.com/1138720556Gary/p/9374511.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!