Serialize () serialization _ javascript Technique in JQuery

Source: Internet
Author: User
This article mainly introduces serialize () serialization in JQuery, which is very detailed and comprehensive. We recommend this article to you: In jQuery, when we use ajax, it is often necessary to assemble the input data to be sent to the server in the form of Key-Value pairs (Key/Value). The JQuery serialize method can be used to easily complete this task, this method can be used to serialize a form into a key-Value Pair (key1 = value1 & key2 = value2 ...) And then submit. The following describes how to use serialize () in JQuery.

I. serialize () Definition and usage:

The serialize () method creates a standard URL-encoded text string by serializing the form value. Its operation object is a jQuery object representing the form Element Set. You can select one or more form elements (such as input or text box) or form elements. Serialized values can be used in URL query strings when an AJAX request is generated.

Syntax:


The Code is as follows:


$ (Selector). serialize ()

Detailed description

1. The serialize () method creates a text string encoded with a standard URL. Its operation object is a jQuery object that represents the form Element Set.

2. The serialize () method can operate jQuery objects that have selected individual form elements, for example,

3. Only "successful controls" are serialized as strings. If the button is not used to submit a form, the value of the submit button is not serialized. To include the value of a form element in a sequence string, the element must use the name attribute.

4. The name in form cannot use keywords in Js or jquery.

Example: length


The Code is as follows:



// Use: $ ("# form1"). serialize ();

The value cannot be obtained.

Ii. serialize () instance in JQuery

1. ajax serialize ()


The Code is as follows:


$. Ajax ({
Type: "POST ",
DataType: "json ",
Url: ajaxCallBack,
Data: $ ('# myForm'). serialize (), // ID of the form to be submitted
Success: function (msg ){
Alert (msg );
}
});

2. serialize () serialized form instance


The Code is as follows:

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.