ajax 跨域 jsonp 处理
2015-01-21 11:57
309 查看
客户端
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>Untitled Page</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <script type="text/javascript"> jQuery(document).ready(function(){ $.ajax({ type : "get", async:false, url : "http://apis.map.qq.com/ws/geocoder/v1/?location=39.984154,116.307490&key=SBDBZ-D2HH4-O6FUD-XCUUY-C5SZ7-QXBWC&get_poi=0&output=jsonp", dataType : "jsonp", jsonp:"aa", //一般为callback jsonpCallback:"QQmap",//自定义的jsonp回调函数名称,默认为jQuery自动生成的随机函数名 success : function(json){ alert(json.status); alert(json); }, error:function(){ alert('fail'); } }); }); </script> </head> <body> </body> </html>
jsonp jsoncallback 说明,最后会在url后加上对应的参数
响应处理
php服务端
<?php //服务端返回JSON数据 $arr=array('a'=>1,'b'=>2,'c'=>3,'d'=>4,'e'=>5); $result=json_encode($arr); //动态执行回调函数 $callback=$_GET['callback']; echo $callback."($result)";
相关文章推荐
- jquery 源码分析8-ajax(D)JSONP跨域处理
- ajax的跨域处理之JSONP
- ajax jsonp跨域处理问题
- jquery中的ajax处理跨域问题-之-----jsonp
- java 处理跨域问题(ajax使用jsonp)
- jquery处理ajax跨域问题方法(三)--jsonp详解(转)
- ajax 跨域处理 jsonp
- AJAX 跨域请求 - JSONP获取JSON数据
- 跨域请求之jQuery的ajax jsonp的使用解惑
- 跨域请求之jQuery的ajax jsonp的使用解惑
- Jquery版Ajax利用JSONP 跨域POST/GET传输数据研究
- 利用JQuery jsonp实现Ajax跨域请求 .Net 的*.handler 和 WebService,返回json数据
- ajax跨域之JSONP
- AJAX的跨域与JSONP(为文章自动添加短址的功能)
- (转)AJAX 跨域请求 - JSONP获取JSON数据
- AJAX 跨域请求 - JSONP获取JSON数据
- AJAX 跨域请求 - JSONP获取JSON数据
- 利用JQuery jsonp实现Ajax跨域请求 .Net 的*.handler 和 WebService,返回json数据
- 关于JQuery 中$.ajax函数利用jsonp实现Ajax跨域请求ASP.NET的WebService成功获取数据的案例
- AJAX的跨域与JSONP(为文章自动添加短址的功能)