Home > Web Front-end > JS Tutorial > body text

jquery ajax fails to pass array to background

一个新手
Release: 2017-09-18 09:17:36
Original
1910 people have browsed it

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"

##12ckee##m2[name]##m2[list][]y1z1o1
#name nihao
##list[] [3]
##0 x
y
z
o
zzzzz
[3 ]##0
x1 ##1
##2
m2[ckee]

If set to true, the submission will be "selectUsers=value&selectUsers=value"

##1##2ckeem2The explanation of the official document is as follows: traditional Type: Boolean
## name nihao
##list [3]
##0##x
y
z
o
[object+Object] This way the background can use String[] ids=request.getParameterValues("selectUsers"); Get the value.
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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template