时间:2021-07-18 08:25:33 | 栏目:jquery | 点击:次
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');
后端接收,以springboot为例:
@RequestParam(name = "resArray[]", required = false) String[] resArray
resArray[] 必须这样写!
实例补充:
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... } });
后台controller代码(SpringMVC)
@ResponseBody @RequestMapping(value = "/box/changeLock") public String changeLock(final Long[] boxIds, final int boxType) { return locker_ChangeLockService.changeLock(boxIds, boxType); }