前言
新人之前学过ajax,但是没有在工作到用到过,最近在工作用到了ajax,记录一下
上代码
$.ajax({
url: "${base}/statistics/updateAllCount", //接收地址
type: "POST", //表格的数据
data: {userName: $("input[name='s_userName']").val(),city: $("input[name='s_city']").val()}, //数据
dataType: "json",//格式
async: false,//默认ftrue,异步方式
success: function (res) {
if(res.success){
console.info(res.data);
//改变表格以后的数据
$("table th:eq(11)").html(res.data.allReceiveMail).css("text-align","center");
$("table th:eq(10)").html(res.data.allSendMail).css("text-align","center");
$("table th:eq(9)").html(res.data.uservisitOAatAll).css("text-align","center");
$("table th:eq(8)").html(res.data.queryStatisticsOACount).css("text-align","center");
layer.msg(res.message);
}
}
error: function (er) {
console.log(er.data);
}
});
Controller层的代码
/* 用户统计表更新总合计数*/
@PostMapping("updateAllCount")
@ResponseBody
public RestResponse updateAllCount(Statistics statistics){
Map map = null;
try{
map = showService.updateUserStatisticsCount(statistics);
}catch (Exception e){
e.printStackTrace();
return RestResponse.failure("系统错误");
}
return RestResponse.success().setData(map);
}