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]
|
##0 x |
|
##1
y
| |
2
z
|
|
ckee
o
|
|
##m2[name]
zzzzz
|
| ##m2[list][]
[3 |
]##0 |
x1
|
##1 |
y1
|
##2
|
z1
|
m2[ckee]
|
o1
If set to true, the submission will be "selectUsers=value&selectUsers=value"
## name
|
nihao
|
##list
|
[3]
|
##0##x
|
|
##1
y
|
| ##2
z |
| ckee
o
|
| m2
[object+Object]
|
This way the background can use String[] ids=request.getParameterValues("selectUsers"); Get the value. | The explanation of the official document is as follows: traditional Type: Boolean If you want to serialize data in the traditional way, then set it to true.
Set this to true if you wish to use the traditional style of param serialization
frontend 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;
}
}); Copy after login Backstage [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!