现在的位置: 首页 > 综合 > 正文

js访问一个服务获取json数据

2013年02月25日 ⁄ 综合 ⁄ 共 2515字 ⁄ 字号 评论关闭
js获取客户端IP及地理位置
 php获取方法:
  1. 1.<?php     
  2. 2.function get_ip_place(){     
  3. 3.$ip=file_get_contents("http://fw.qq.com/ipaddress");     
  4. 4.$ip=str_replace('"',' ',$ip);     
  5. 5.$ip2=explode("(",$ip);     
  6. 6.$a=substr($ip2[1],0,-2);     
  7. 7.$b=explode(",",$a);     
  8. 8.return $b;     
  9. 9.}     
  10. 10.$ip=get_ip_place();     
  11. 11.print_r($ip);     
  12. 12.?>    


 

js获取

DEMO:http://blog.suiyidian.cn/texiao/ipd.html

腾讯的IP地址API接口地址:http://fw.qq.com/ipaddress
返回的是数据格式为:var IPData = new Array(“114.218.183.139″,”",”北京市”);
使用JS代码进行调取:

[javascript] view
plain
copyprint?

  1. <script language="javascript" type="text/javascript" src="http://fw.qq.com/ipaddress">  
  2. </script>    
  3.  <script>document.write("你的IP是:"+IPData[0]+",来自:"+IPData[2]);  
  4. </script>   


腾讯IP,转UTF-8:

[javascript] view
plain
copyprint?

  1. <script type="text/javascript" src="http://fw.qq.com/ipaddress" charset="gb2312"></script>  
  2.   
  3. $(document).ready(function() {  
  4.   
  5.     $("#ip").val(IPData[0]);  
  6.     $("#add").val(IPData[2]);  
  7. })  


 

 

其它获取方法:

新浪的IP地址查询接口:http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js
新浪多地域测试方法:http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip=12.130.132.30
搜狐IP地址查询接口(默认GBK):http://pv.sohu.com/cityjson
搜狐IP地址查询接口(可设置编码):http://pv.sohu.com/cityjson?ie=utf-8
搜狐另外的IP地址查询接口:http://txt.go.sohu.com/ip/soip

  1. 1.<?php     
  2. 2.function get_ip_place(){     
  3. 3.$ip=file_get_contents("http://fw.qq.com/ipaddress");     
  4. 4.$ip=str_replace('"',' ',$ip);     
  5. 5.$ip2=explode("(",$ip);     
  6. 6.$a=substr($ip2[1],0,-2);     
  7. 7.$b=explode(",",$a);     
  8. 8.return $b;     
  9. 9.}     
  10. 10.$ip=get_ip_place();     
  11. 11.print_r($ip);     
  12. 12.?>    


 

js获取

DEMO:http://blog.suiyidian.cn/texiao/ipd.html

腾讯的IP地址API接口地址:http://fw.qq.com/ipaddress
返回的是数据格式为:var IPData = new Array(“114.218.183.139″,”",”北京市”);
使用JS代码进行调取:

[javascript] view
plain
copyprint?

  1. <script language="javascript" type="text/javascript" src="http://fw.qq.com/ipaddress">  
  2. </script>    
  3.  <script>document.write("你的IP是:"+IPData[0]+",来自:"+IPData[2]);  
  4. </script>   


腾讯IP,转UTF-8:

[javascript] view
plain
copyprint?

  1. <script type="text/javascript" src="http://fw.qq.com/ipaddress" charset="gb2312"></script>  
  2.   
  3. $(document).ready(function() {  
  4.   
  5.     $("#ip").val(IPData[0]);  
  6.     $("#add").val(IPData[2]);  
  7. })  


 

 

其它获取方法:

新浪的IP地址查询接口:http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js
新浪多地域测试方法:http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip=12.130.132.30
搜狐IP地址查询接口(默认GBK):http://pv.sohu.com/cityjson
搜狐IP地址查询接口(可设置编码):http://pv.sohu.com/cityjson?ie=utf-8
搜狐另外的IP地址查询接口:http://txt.go.sohu.com/ip/soip

抱歉!评论已关闭.