Example of js Sina IP address interface call

Source: Internet
Author: User
Tags json

The simplest php call

The code is as follows: Copy code

<? Php
$ Ip = "218.192.3.42 ";
$ Json = file_get_contents ("http://int.dpool.sina.com.cn/iplookup/iplookup.php? Format = json & ip = ". $ ip );
$ Json = json_decode ($ json, true );
Echo "ip address:". $ ip;
Echo "Geographic :". $ json ["country"]. $ json ["province"]. $ json ["city"]. $ json ["district"]. $ json ["isp"];
?>

JS code

The code is as follows: Copy code

<Script type = "text/javascript" src = "http://int.dpool.sina.com.cn/iplookup/iplookup.php? Format = js "charset =" utf-8 "> </script>
<Script type = "text/javascript">
Alert (remote_ip_info.country + "" + remote_ip_info.city );
</Script>

Example

The code is as follows: Copy code

<Script type = "text/javascript" src = "http://int.dpool.sina.com.cn/iplookup/iplookup.php? Format = js "> </script>
<Script type = "text/javascript">

Function getIpCity (){
// Obtain the ip address
Var I = remote_ip_info;
// Document. write ('IP range: '+ I ['start'] +'-'+ I ['end'] +' \ r \ n <br/> locations: '+ I ['country'] + I ['Province'] + I ['city'] + I ['isp ']);
$ ("# CityAddress" ).html (I ['city']);
   
};
GetIpCity ();
GetAllProvince ();
Function getAllProvince (){
$ ("# Province"). empty ();
$ ("# Province"). append ("<option value =''> "+" current city "+" </option> ");
// Obtain the province
Var url = baseUrl + "/index/getAllProvince ";
$. Ajax ({
Type: "post ",
Url: url,
Async: false,
DataType: "json ",
Success: function (json ){
If (json! = Null & json. length! = 0 ){
For (var I = 0; I <json. length; I ++ ){
$ ("# Province "). append ("<option value = '" + json [I]. key + "'>" + json [I]. value + "</option> ");
        }
       }
   }
})
};
 
Function changCity (){
Var cityName = $ ("# city option: selected"). attr ("text ");
If (cityName = 'city' | cityName = 'municipal authority '){
$ ("# CityAddress" ).html ($ ("# province option: selected"). attr ("text "));
Return;
} Else if (cityName = "-- Select City --"){
Alert ("Select the right city !! ");
Return;
  }
  
// $ ("# CityAddress" ).html (cityName );
 }
 
</Script>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.