Using Ajax to pass arrays to webservice_jquery in jquery

Source: Internet
Author: User

In the project need to use Ajax to pass the array data, and in the background with a list of objects to receive, the main problem is how to construct data transmission, in the same way as the common Ajax pass character data, the code is written as follows
JS Code:

var righttypes=["A", "B", "C"];
var regioncode= "";
 $.ajax ({
                type: POST),
                URL: "/service/lsprtapi.asmx/getstaticbyrighttypesandregioncode",
                dataType: ' JSON ',
                data:{"righttypes": Righttypes, "Regioncode": Regioncode},
                contentType: "Application/json; Charset=utf-8 ",
                success:function (data) {
                    var src = json.parse (DATA.D);

                },
                error:function () {
                }
            });

Observe the data passed in the browser as shown above:

The data passed by the "&" connection, is not the desired result, after consulting the data, modify the data as follows:

Data:JSON.stringify ({"Righttypes": Righttypes, "Regioncode": Regioncode})

Background code:

[WebMethod]
        public string Getstaticbyrighttypesandregioncode (list<string> righttypes, string regioncode)
        {
            int Icount=righttypes. Count;
            Return "Success";
        }

After testing, the data can be normally obtained, for the use of Ajax to pass the array and objects and other complex data content, you can refer to the blog, a more comprehensive introduction
http://cnn237111.blog.51cto.com/2359144/984466

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.