JSONP跨域访问
来源:互联网 发布:大学英语教材听力软件 编辑:程序博客网 时间:2024/05/22 02:22
Extra JS
Import JQuery, JSON and JQuery-JSONP.
Client
1) access with JSONP
function testJSONP(para1, para2) {// generate a parameter JSON objectvar para = [ {'para1' : para1,'para2' : para2} ];var URL = "www.xxx.com/xxx";$.ajax({type : "get",cache : false,url : URL + "/method.do",data : $.param(para[0]),dataType : "jsonp",jsonp : "callBackFun",contentType : "application/x-javascript;charset=UTF-8",success : function(data) {// return article JSON listalert("success");},error : function(data) {// ERRORalert("error");}});}
2) access with JQuery-JSONP
function testJSONP(para1, para2) {// generate a parameter JSON objectvar para = [ {'para1' : para1,'para2' : para2} ];var URL = "www.xxx.com/xxx";$.jsonp({ url: URL + "/method.do", data: $.param(para[0]), callbackParameter: "callBackFun", success: function (data) { alert("success"); }, error: function (xOptions, textStatus) { alert("error"); }});}
Server
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception{request.setCharacterEncoding("UTF-8");// result objectObject object = new Object();// change object to JSON StringJSONObject jsonObject = JSONObject.fromObject(object);String resultStr = jsonObject.toString();// Add callback function to JSON StringString callBackFun = request.getParameter("callBackFun");if(callBackFun != null)resultStr = callBackFun + "(" + resultStr + ")";// return JSON to Clientresponse.setHeader("Cache-Control", "no-cache");response.setContentType("application/x-javascript;charset=UTF-8");response.getWriter().print(resultStr);return null;}
- jsonp 跨域访问
- JSONP跨域访问
- jsonp跨域访问
- Jsonp 跨域访问
- 跨域访问jsonp
- Jsonp 跨域访问
- JSONP 跨域访问
- Jsonp 跨域访问
- jsonp跨域访问
- jsonp跨域访问
- 跨域访问 jsonp
- JSONP跨域访问
- jsonp跨域访问
- JSONP 跨域访问
- 跨域访问jsonp
- jsonp跨域访问
- jsonp 跨域访问
- jsonp跨域访问
- Run-Time Check Failure #2 - Stack around the variable 'dlg1' was corrupted.
- UVa 572/POJ 1562/HDU 1241 Oil Deposits(DFS,两种写法)
- 用友 NC客户化开发手册
- 快速安装PHP-Mysql
- 常用查询入口[保持更新ing]{请善待Ctrl+F}
- JSONP跨域访问
- T-SQL循环语句
- 博客开通
- 初学者如何查阅自然语言处理(NLP)领域学术资料
- android sdcard创建使用
- 8G服务器磁盘控制卡识别及Windows 2003驱动制作
- io流实现文件的复制
- 2013.8.3 android 版本分支列表
- 菜鸟学asp.net遇到的问题和解决方案