[英]Javascript : detect real IP address
我使用“ EasyJQuery”使用以下脚本来检测用户的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版本,没有Java版本。
那么,该图书馆真的不再受支持吗? 如果是,是否有类似的方法?
先感谢您。
从您链接到的页面:
// 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);
})
$.ajax({
url: '//freegeoip.net/json/',
type: 'POST',
dataType: 'jsonp',
success: function(location) {
console.log(location);
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.