繁体   English   中英

jQuery 显示/获取用户IP地址

[英]jQuery show/get the user IP address

最近,我开始学习jQuery ,我想创建一个简单的脚本来显示用户 IP。但是,我编写的代码不起作用,遗憾的是我的知识不足以自己找到问题。 这就是为什么如果有人能帮助我,我将非常感激。

代码:

 $.getJSON("http://ip-api.com/json/?callback=?", function (data) { console.log(data); $('#IP_Address').append("Your IP: " + data.query); $('#Country').append("Your Country: " + data.country); $('#City').append("Your City: " + data.city); });
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="IP_Address"></div> <div id="Country"></div> <div id="City"></div>

尝试这个

 <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script> $.getJSON("http://ip-api.com/json/?callback=?", function (data) { console.log(data); $('#IP_Address').append("Your IP: " + data.query); $('#Country').append("Your Country: " + data.country); $('#City').append("Your City: " + data.city); }); </script> </head> <body> <div id="IP_Address"></div> <div id="Country"></div> <div id="City"></div> </body> </html>

复制所有文本,在您的计算机中安装 WampServer 并找到您的文件夹“www”,创建一个文件 pruebahtml.php,在您的 web 浏览器中写入 http://localhost/pruebahtml.php 并显示给我

给我看看

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM