jquery向后台提交数组的代码分析

在本篇文章里小编给大家整理的是一篇关于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); }

以上就是jquery向后台提交数组的代码分析的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » JavaScript 教程