起初我認為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 |
如果設定成true,則提交時會是"selectUsers=value&selectUsers=value"
namenihao | |
list | ##[3 |
0 | |
x | #1 |
y | 2 |
z | ckee |
o
[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中文網其他相關文章!