jsonp的使用
来源:互联网 发布:有赞微商城和淘宝区别 编辑:程序博客网 时间:2024/06/05 15:19
1.Javascript的写法:jsonp只有get方法,post方法使用的方式跟get一样
$.ajax({
type : 'post',
async : false,
url : baseUrl+'?callback=jsonpCallback',
cache : false,
data:params,
dataType : "jsonp",
jsonp: 'jsonpCallback',
success : function(data) {
}
});
简写:
- $.getJSON("http://app.example.com/base/json.do?jsonpCallback=?",
- function(data){
- });
java后台需要返回一个和回调函数名相同的方法,需要在response设置返回编码,不然会出现中文乱码
@ResponseBody
@RequestMapping("enterprise/sendMailByWeek.html")
public void sendMailByWeek(HttpServletRequest request,HttpServletResponse response ,String previousMonth,String startStr ,String endStr ,String id){
try {
response.setContentType("text/plain");
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
response.setCharacterEncoding("utf-8");
Map<String,Object> param = new HashMap<>();
param.put("id", id);
List<EnterpriseVo> entList = sendMessageService.queryAllEnterprise(param);
List<EnterpriseSwap> entSwapList = sendMessageService.queryEnterpriseSwapByWeek(startStr);
String Time = "week";
String msgTime = "(" + startStr + "至" + endStr + ")业户周考核统计";
boolean flag = false;
List<Map<String,Object>> result = sendMessageService.sendMail(entList,entSwapList,msgTime,Time,flag);
PrintWriter out = response.getWriter();
Object resultJSON = JSONObject.toJSON(result.get(0)); //根据需要拼装json
String jsonpCallback = request.getParameter("jsonpCallback");//客户端请求参数
out.println(jsonpCallback+"("+resultJSON+")");//返回jsonp格式数据
out.flush();
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
- jsonp的使用实例
- jsonp接口的使用
- jsonp的使用
- JsonP的使用
- jsonp的使用
- Jsonp的使用
- jsonp的使用
- jsonp 跨域的使用
- jsonp 的原理和使用
- Spring 4.1+ 的 JSONP使用
- jsonp和callback的使用
- jsonp的概念与使用
- jsonp和callback的使用
- 关于JSONP的原理和JQ中使用JSONP
- jsonp使用,spring4.x对jsonp的支持
- 关于JSONP的原理和JQ中使用JSONP
- jsonp使用
- jsonp使用
- 【codevs 1742】爬楼梯
- Java:object类 中常用equals()和 toString()方法的重写
- PullToRefreshListView
- C#多线程
- leetcode 561 Array Partition I
- jsonp的使用
- 轮播图
- 移动端页面上拉加载、下拉刷新插件
- cyclictest源码分析
- Array Map, Filter and Reduce in JS 牛x的讲解 in js
- BZOJ3884 上帝与集合的正确用法 [欧拉函数]
- hadoop HA +zookeeper +yarn
- 转自TheLJT 旧日本海军建军思路与用兵思路的研究
- ES 基本使用《一》--分析