后台ajax
var check = [];
$('#datagrid').find(':checkbox').each(function(){
if($(this).is(':checked')){
check.push($(this).val());
}
});
var row = {};
row['adminIds'] = check;
row['adminIdOlds'] = oldCheck;
row['roleId'] = $("#roleId").val();
$.ajax({
url : '${ctx}/admin/authorizedUser',
type : 'post',
data : JSON.stringify(row),
headers: { 'Accept': 'application/json','Content-Type':'application/json' },
datatype: 'json',
success : function(data) {
showAlert(data);
if(data.status=="success"){
parent.modal.close();
}
},
error : function() {
dangerAlert();
}
});
后台接收使用@RequestBody
使用对象来接受
若后台ajax改为如下:即去掉headers定义
var check = [];
$('#datagrid').find(':checkbox').each(function(){
if($(this).is(':checked')){
check.push($(this).val());
}
});
var row = {};
row['adminIds'] = check;
row['adminIdOlds'] = oldCheck;
row['roleId'] = $("#roleId").val();
$.ajax({
url : '${ctx}/admin/authorizedUser',
type : 'post',
data : row,
datatype: 'json',
success : function(data) {
showAlert(data);
if(data.status=="success"){
parent.modal.close();
}
},
error : function() {
dangerAlert();
}
});
则后台接收可使用
@ResponseBody
@RequestMapping("authorizedUser")
public Map authorizedUser(@RequestParam(value = "adminIds[]", required = true) String[] adminIds,
@RequestParam(value = "adminIdOlds[]", required = true) String[] adminIdOlds) {
}