2013-09-26 176 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獲取訪問者的位置(即城市) –