Example analysis of jquery serialization method _jquery

Source: Internet
Author: User

This example describes the jquery serialization method. Share to everyone for your reference. The specific analysis is as follows:

When you do Ajax, you often need to serialize,
Serialize () can only serialize the form. (Note: The contents of the form can only be used with name)

Now there is an object:

Copy Code code as follows:
var obj={a:1,b:2,c:3};

How do we get it serialized?
Prototype can be done with $h (obj). toquerystring ()? Is there any way jqueyr?

The answer is yes, jquery provides the $.param ().

var obj={a:1,b:2,c:3};
var k = $.param (obj);
Alert (k)/Output a=1&b=2&c=3

OK, let's try it. ^_^.

Examples of serialize serialization.

1. jquery Selector Select all input in the form (type is text and radio)
2. Serialize () to serialize it

var msg = $ ("#innerbox Input[type=text], #innerbox Input[type=radio]"). Serialize ();
$.ajax ({
type: "POST",
URL: "add.php",
data:msg,
success:function (data) {$ (". ShowMsg"). HTML ( data); }
});

I hope this article will help you with your jquery programming.

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.