At first I thought traditional:true was dispensable, but later when I didn’t use traditional, I found that the value of selectUsers could not be obtained in the background, so it is certain that the default value of traditional is false.
When the submitted parameter is an array ({selectUsers:[value,value,value]}),
If it is false, it will be submitted when Is "selectUsers[]=value&selectUsers[]=value"
| #name | nihao | |||||||||||||
| ##list[] | [3] | |||||||||||||
| ##0x | ||||||||||||||
| y | ||||||||||||||
| z | ||||||||||||||
| o | ||||||||||||||
| zzzzz | ##m2[list][] | |||||||||||||
| [3 | ]##0 | |||||||||||||
| x1 | ##1 | |||||||||||||
| ##2 | ||||||||||||||
| m2[ckee] | ||||||||||||||
If set to true, the submission will be "selectUsers=value&selectUsers=value"
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; } });
Copy after login
[HttpPost] public string SubmitForm(mymode request) { if (request != null) { // } return "操作成功。"; }
Copy after login
|
The above is the detailed content of jquery ajax fails to pass array to background. For more information, please follow other related articles on the PHP Chinese website!