jquery Ajax () method to submit array problem

Source: Internet
Author: User

When a parameter is submitted to the background with $.ajax (), the array in the parameter is generally received in the background by an array object such as list, or integer[].

Like what:

$.ajax ({
Type: "POST",
Url:url,
data:{gender:[0,1]},
DataType: "JSON",
Async:false
});

Here's an array of gender to query for sex.

When you use Firefox's firebug to view post data, if the jquery version is too high, you'll find gender submitting the following types

Schgender[] 1

schgender[] 0

That is, it treats each element in the array as an array. This way to the background will be an error.

The solution is to switch to a lower version of jquery, and I'll have no problem replacing it with 1.3.2 (not recommended). And then look at the post data:

Schgender 1

Schgender 0

The best solution is to add a property

traditional:true

$.ajax ({
Type: "POST",
Url:url,

Traditional:true,
data:{gender:[0,1]},
DataType: "JSON",
Async:false
});

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.