如何在 Jquery 或 Phonegap 中获取 IP 地址?
我正在为 Android、Iphone 和 Windows 开发跨平台应用程序。
我需要找到请求的IP地址。
这很简单! ;)
$.getJSON("http://jsonip.appspot.com",
function(data){
alert( "Your ip: " + data.ip);
});
如果你不想使用http://jsonip.appspot.com
并且您可以在服务器上运行 php,只需替换http://jsonip.appspot.com http://jsonip.appspot.com with http://domain/ip.php
, where ip.php
是这样的:
ip.php
<?php
echo json_encode(array("ip"=>$_SERVER['REMOTE_ADDR']));
?>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)