【发布时间】:2016-06-30 04:24:19
【问题描述】:
我不知道如何从访问我网页的访问者那里获取国家/地区代码。我见过很多其他的例子,但没有一个使用纯 Javascript。这是我当前的代码:
<!DOCTYPE html>
<html lang="en-US">
<head>
</head>
<body>
<script type="text/javascript">
var userip;
</script>
<script type="text/javascript" src="https://l2.io/ip.js?var=userip"> </script>
<script type="text/javascript">
document.write("IP: ", userip);
$.get("http://ipinfo.io/"+userip.text(), function (response) {
reg.text("country code here" + response.country);
}, "jsonp");
</script>
</body>
</html>
我使用 jQuery 的 $.get 方法从 JSONP 请求中获取用户的 IP 地址到 ipinfo.io。
不幸的是,l2.io.js 目前除了 ip 没有返回任何东西。
如果有人可以提供帮助或有任何示例,请链接所有需要的相关 JavaScript 库。谢谢。
【问题讨论】:
标签: javascript jquery html sample ip-geolocation