js传递数组到后台
2017-01-13 14:31
309 查看
今天一位同事碰到了这个问题,相互讨论了下,记录下备忘
方法一:
1.使用JSON.stringify 将数组对象转化成json字符串;
2.传输过程中参数
3.后台处理
方法二:
1.前端不做处理:
2.传输过程中参数
3.后台处理
注:两种post请求的content-type不同。
方法一:
1.使用JSON.stringify 将数组对象转化成json字符串;
var array = ["1", "2"]; $.ajax({ type : 'POST', url: path + '/check/testPost', contentType : "application/json" , data : JSON.stringify(array), success : function(data) { } });
2.传输过程中参数
3.后台处理
@RequestMapping(value = "/testPost", method = {RequestMethod.POST}) public void testPost(@RequestBody String[] array) throws IOException { for (String string : array) { System.out.println(string); } return ; }
方法二:
1.前端不做处理:
var array = ["1", "2"]; $.ajax({ type : 'POST', url: path + '/check/testPost', contentType: "application/x-www-form-urlencoded", data: {"array": array}, success : function(data) { } });
2.传输过程中参数
3.后台处理
@RequestMapping(value = "/testPost", method = {RequestMethod.POST}) public void testPost(HttpServletRequest req) throws IOException { String[] array = req.getParameterValues("array[]"); for (String string : array) { System.out.println(string); } return ; }
注:两种post请求的content-type不同。
相关文章推荐
- JFinal+JS向后台传递数组的方法
- js将json数组传递到后台及接收
- js获取后台传递的数组
- JS当中的数组如果通过JSON格式传递到后台
- js前台传递json字符串数组到后台有后台转换成list集合或其他格式的问题解决
- js传递数组到后台
- JS向后台传递json数组对象
- .net 后台传递数组给js
- js传递数组给java后台
- 【ajax传递数组】从js到控制器后台,到mybatis,教你如何传递数组,项目中直接截图,springMVC结构
- js传递数组参数到后台controller的方法
- js/jquey.ajax传递二位数组到java后台
- JS传递数组到后台
- js传递数组参数到后台controller
- js传递数组到后台
- js传递数组到后台
- 关于“Asp.net 中后台CS读取数据库数据生成数组传递给前台页面JS使用”
- JQuery Ajax向后台传递数组
- js数组传值,提交时到后台用string接受数组形式字符串
- 前台页面以url形式向后台传递数组