2013-09-26 131 views
0

我所用“EasyJQuery”来检测用户的IP地址,并使用下面的脚本的其他信息:的Javascript:检测真实IP地址

<!-- Require jQuery/Anyversion --><script type="text/javascript" language="Javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> 
<!-- Require EasyJQuery After JQuery --><script type="text/javascript" language="Javascript" src="http://api.easyjquery.com/easyjquery.js"></script> 
<script type="text/javascript" language="Javascript"> 
    // 1. Your Data Here 
    function my_callback(json) { 
     alert("IP :" + json.IP + " nCOUNTRY: " + json.COUNTRY); 
    } 

    function my_callback2(json) { 
     // more information at http://api.easyjquery.com/test/demo-ip.php 
     alert("IP :" + json.IP + " nCOUNTRY: " + json.COUNTRY + " City: " + json.cityName + " regionName: " + json.regionName); 
    } 

    // 2. Setup Callback Function 
    // EasyjQuery_Get_IP("my_callback"); // fastest version 
    EasyjQuery_Get_IP("my_callback2","full"); // full version 
</script> 

现在,它没有更多的工作。官方页面现在重定向到:ip.codehelper.io和Github库只有一个PHP版本不是Javascript版本。

那么这个库真的不再支持?如果是,是否有类似的?

预先感谢您。

回答

3

从你的页面链接到:

// First, embed this script in your head or at bottom of the page. 
<script src="http://www.codehelper.io/api/ips/?js"></script> 
// You can use it 
<script> 
    alert(codehelper_ip.IP); 
    alert(codehelper_ip.Country); 
</script> 

或者类似的东西,这可能是更好的:

$.getJSON('http://www.codehelper.io/api/ips/?js&callback=?', function(response) { 
    console.log(response.IP, response.Country, response.CityName); 
}) 
+0

工作,谢谢。 – OussamaLord

1
$.ajax({ 
      url: '//freegeoip.net/json/', 
      type: 'POST', 
      dataType: 'jsonp', 
      success: function(location) { 
       console.log(location); 
       } 
     }); 
+0

请添加关于您的代码块对您的回答所做的简要说明 – GNi33

+0

使用JavaScript获取访问者的位置(即城市) –