w3c对post()方式的定义
post()方式是jquery封装的AJAX,使用起来比传统的AJAX要简洁.适用于大部分开发需求.
JS Demo
//提交审核
function toChecked(documentId){
$.dialog.confirm('您确定提交至财务审核么?', function(r) {
var url = "projectMainAttController.do?submitToChecked";
var data = {documentId:documentId};
$.post(url,data,function(res){
var resObj=$.parseJSON(res);//如果指定post的JSON参数,则不用转换
if(resObj.success){
window.location.reload();//刷新页面
}
})
});
}
后台代码.开发语言JAVA.MVC框架是SpringMVC.
controller代码
/**
* 提交审核
*
* @return
*/
@RequestMapping(params = "submitToChecked")
@ResponseBody
public AjaxJson submitToChecked(String documentId, HttpServletRequest request) {
String message = null;
AjaxJson j = new AjaxJson();
ProjectMainAttEntity projectMainAtt = systemService.getEntity(ProjectMainAttEntity.class, documentId);
projectMainAtt.setCheckedStatus("1");
message="提交审核成功!";
try{
projectMainAttService.updateEntitie(projectMainAtt);
systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
}catch(Exception e){
e.printStackTrace();
message="提交审核失败!";
throw new BusinessException(e.getMessage());
}
j.setMsg(message);
return j;
}
注意!
JSON方式的请求,在对应的方法上要加@responseBody 标签
返回类型是一个常用的AJAX工具类
AJAX工具类(并生成getter/setter)
private boolean success = true;// 是否成功
private String msg = "操作成功";// 提示信息
private Object obj = null;// 其他信息
private Map<String, Object> attributes;// 其他参数