js中:
$.post("admin/busRedPacket/addRedPacket",data,function(datas) {
var pd=datas.pd;
alert(pd);
alert("增加成功");
window.dialogArguments.location.reload();
},"json");
或者
$.ajax({
type:"post",
url:,
dataType:"json",
success:function(data){
if (data != null) {
var slen = data.length;
}
}else{
}
},
error:function(XMLHttpRequest,textStatus,errorThrown){
alert("请求失败");
}
});
发送整合:
private static void writer(HttpServletResponse response,String str) {
try {
// 设置页面不缓存
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache");
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html");
PrintWriter out = null;
out = response.getWriter();
out.print(str);
out.flush();
out.close();
} catch (IOException e) {
e.printstacktrace();
}
}
后台不是集合:
JSONObject json=new JSONObject();
json.put("msg","恭喜130xxx7893获得车子");
writer(response,json.toString());或者response.getWriter().write(json.toString());
传值为集合:
writer(response,JSON.toJSONString(list));
需要导入包: