Use jquery to get the API interface and then return to the array.
code is as follows |
copy code |
$ (function ( { $ ("#btnGetIP"). Click (function () { var jqxhr = $.getjson ("http://jsonip.appspot.com?callback=?", function (data) { alert (DATA.IP); }) . Error (function () {alert ("error");}) }); }); |
Another way to use Ajax
The code is as follows |
Copy Code |
/* Access to the IP address URL Http://www.ip.cn/getip.php?action=getip */ function Myobjrequest () { var myhttp=null; Try { Myhttp = new ActiveXObject ("Msxml2.xmlhttp"); } catch (IE) { try{ Myhttp = new ActiveXObject ("Microsoft.XMLHTTP"); } catch (Huohu) { Myhttp = new XMLHttpRequest (); } } return myhttp; } function Getipdata () { var url = "Http://www.ip.cn/getip.php?action=getip"; var myobj = Myobjrequest (); Myobj.open ("Get", url,true); Myobj.onreadystatechange = function () { if (myobj.readystate = = 4) { if (Myobj.status = = 200) {//read data is correct var Address=myobj.responsetext; Only judge the first time into uewang.com if (Document.referrer.indexOf ("uewang.com") <0) { if (Address.indexof ("Guangzhou, Guangdong Province") >0) { Window.location.href= "Http://www.111cn.net"; } else if (Address.indexof ("Shenzhen, Guangdong Province") >0) { Window.location.href= "Http://www.111cn.net"; } } Other: Shenzhen city, Guangdong province } else { "Error getting local IP, please refresh this page or contact admin!" } } else { Loading in Please wait ... } } Myobj.send (NULL) } Getipdata (); |