方法一:
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不同。


网友评论文明上网理性发言 已有0人参与
发表评论: