起初我认为traditional:true,可有可无,但是后来不用traditional的时候,发现后台无法获取selectUsers的值,那么可以肯定的是traditional默认值是false.
当提交的参数是数组( {selectUsers:[value,value,value]} ),
如果是false的话,则提交时会是"selectUsers[]=value&selectUsers[]=value"
name | nihao |
list[] | [3] |
0 | x |
1 | y |
2 | z |
ckee | o |
m2[name] | zzzzz |
m2[list][] | [3] |
0 | x1 |
1 | y1 |
2 | z1 |
m2[ckee] | o1 |
如果设置成true,则提交时会是"selectUsers=value&selectUsers=value"
name | nihao |
list | [3] |
0 | x |
1 | y |
2 | z |
ckee | o |
m2 | [object+Object] |
这样后台就能用String[] ids=request.getParameterValues("selectUsers"); 获取到值。
官方文档的解释如下:
traditional
类型:Boolean
如果你想要用传统的方式来序列化数据,那么就设置为 true。
Set this to true if you wish to use the traditional style of param serialization
前台js
var obj2 = { "name": "nihao", "list": ["x", "y", "z"], "ckee": "o", "m2": { "name": "zzzzz", "list": ["x1", "y1", "z1"], "ckee": "o1" } } $.ajax({ type: "POST", url: "/Home/SubmitForm", data: obj2, dataType: "text", async: false, traditional: true, success: function (data) { var rows = data.rows; } }); $.ajax({ type: "POST", url: "/Home/SubmitForm", data: obj2, dataType: "text", async: false, traditional: false, success: function (data) { var rows = data.rows; } });
后台
[HttpPost] public string SubmitForm(mymode request) { if (request != null) { // } return "操作成功。"; }
以上是jquery ajax 传递数组到后台失败的问题的详细内容。更多信息请关注PHP中文网其他相关文章!