jsonp+jquery示例代码,jsonp是什么?看完了还不会我就给你跪了.....
2015-07-15 17:48
671 查看
jsonp+jquery示例代码,jsonp是什么?看完了还不会我就给你跪了.....
文件与目录结构:
|---jsonp
|-----------json.php
|-----------jsonp.php
|-----------test.php
代码如下:
test.php
json.php
jsonp.php
文件与目录结构:
|---jsonp
|-----------json.php
|-----------jsonp.php
|-----------test.php
代码如下:
test.php
<!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>JSIONP TEST</title> <script src="http://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js"></script> <script type="text/javascript"><!-- /* //跨越ajax请求无法执行demo jQuery(document).ready(function(){ $.ajax({ type: "get", url: "http://company.test.com/jsonp/json.php", dataType: "json", data: "callbackparam=jsonpCallback", success: function(json){ alert('json:' + json); }, error: function(){ alert('fail'); } }); }); */ //使用jsonp可以解决问题 jQuery(document).ready(function(){ $.ajax({ type: "get", url: "http://company.test.com/jsonp/jsonp.php", dataType: "jsonp", jsonp: "callbackparam", jsonpCallback:"jsonpCallback", success: function(json){ alert('json:' + json); }, error: function(){ alert('fail'); } }); }); </script> </head> <body> </body> </html>
json.php
<?php $funame = $_GET['callbackparam']; echo '{"name": "cxh", "sex": "man"}';
jsonp.php
<?php $funame = $_GET['callbackparam']; echo $funame.'({"name": "cxh", "sex": "man"})';
相关文章推荐
- struts2中用jquery、ajax实现下拉框的级联
- jquery动态创建表格
- 自定义jQuery插件Step by Step
- JQuery的animate
- jQuery插件开发模式
- Jquery插件开发 详细
- jQuery插件开发的五种形态小结
- 文章标题jquery的this与$(this)的区别与联系
- jquery与Dom元素的互换
- 深入理解jQuery插件开发
- Jquery 获取IP地址
- jquery innerHeight(),outerHeight(),height()的区别
- 看了两天jquery 插件的写法练手解决placeholder不兼容问题
- jquery中取消和绑定hover事件的正确方式
- jQuery--工具函数
- JavaScript封装Ajax(类JQuery中$.ajax()方法)
- 超炫的时间轴jquery插件Timeline Portfolio
- jQuery 鼠标滚轮插件 jquery.mousewheel.js
- jQuery each,避免使用js for循环
- jquery 选择器