如何分析使用jQuery向后端发送数组数据的代码实现?

更新于
2026-09-27 01:25:33
1阅读来源:SEO问题
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计236个文字,预计阅读时间需要1分钟。

如何分析使用jQuery向后端发送数组数据的代码实现?

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

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); }

以上就是易盾网络小编结合多篇后整理的相关内容,希望能够帮助到大家。

本文共计236个文字,预计阅读时间需要1分钟。

如何分析使用jQuery向后端发送数组数据的代码实现?

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

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); }

以上就是易盾网络小编结合多篇后整理的相关内容,希望能够帮助到大家。