jquery:向后台提交数组
var resArray = new Array(1,2,3);$.post(prefix + '/save/res/', {

'roleID' : $('#roleID').val(),

'resArray' : resArray,

}, function(result) {

top.closeLayer();

if (result.state == 'succ') {

top.refreshRight();

top.okLayer('维护角色', '保存数据成功');

} else {

top.errorLayer('维护角色', '保存数据失败');

}

}, 'json');
var resArray = new Array(1,2,3);$.post(prefix + '/save/res/', {

'roleID' : $('#roleID').val(),

'resArray' : resArray,

}, function(result) {

top.closeLayer();

if (result.state == 'succ') {

top.refreshRight();

top.okLayer('维护角色', '保存数据成功');

} else {

top.errorLayer('维护角色', '保存数据失败');

}

}, 'json');后端接收,以springboot为例:
@RequestParam(name = "resArray[]", required = false) String[] resArray
@RequestParam(name = "resArray[]", required = false) String[] resArrayresArray[] 必须这样写!实例补充:实例补充jQuery.ajax向后台传递数组问题
//创建一个测试数组
var boxIds = new Array();
boxIds.push(12182);
boxIds.push(12183);
boxIds.push(12184);
//向后台交互
$.ajax({

url: "/xxx",

type: "GET",

data: {

"boxIds": boxIds,

"boxType": 0,

"time": new Date().getTime()

},

success: function(data) {

//do sth...

}
});
//创建一个测试数组
var boxIds = new Array();
boxIds.push(12182);
boxIds.push(12183);
boxIds.push(12184);
//向后台交互
$.ajax({

url: "/xxx",

type: "GET",

data: {

"boxIds": boxIds,

"boxType": 0,

"time": new Date().getTime()

},

success: function(data) {

//do sth...

}
});后台controller代码(SpringMVC)
@ResponseBody
@RequestMapping(value = "/box/changeLock")
public String changeLock(final Long[] boxIds, final int boxType) {

return locker_ChangeLockService.changeLock(boxIds, boxType);
}
@ResponseBody
@RequestMapping(value = "/box/changeLock")
public String changeLock(final Long[] boxIds, final int boxType) {

return locker_ChangeLockService.changeLock(boxIds, boxType);
}以上就是小编结合多篇后整理的相关内容,希望能够帮助到大家。