jquery form Serialization

Source: Internet
Author: User

1. Serializing a URL-encoded text string

var serialize = $ ("form[name=testform]"). Serialize (); Console.log (serialize);

The. Serialize () method creates a text string that is represented as a standard URL encoding. Its operand is a JQuery object that represents a collection of form elements.

Results:

2. Serializing an array of JSON objects

var serializearray = $ ("form[name=testform]"). Serializearray () Console.log (Serializearray);

The Serializearray () method creates an array of objects (names and values) by serializing the form values.

Results:

3. Serializing to a JSON object

(function($) {$.fn.serializejson=function() {        varJSON = {}; varArray = This. Serializearray (); $.each (Array,function() {            varName = This. Name; varValue = This. Value; if(Value = =NULL|| Value = = "") {                return true; }            varOld =Json[name]; if(old) {if($.isarray (old)) {Old.push (value); } Else{Json[name]=[old, value]; }            } Else{Json[name]=value;        }        }); returnJSON; };}) (jQuery);varSerializejson = $ ("Form[name=testform")). Serializejson (); Console.log (Serializejson);

Results:

4.key/value object serialized to a string

var param == 123=console.log (jquery.param (param)); Console.log (Jquery.param ( Serializearray));

The Param () method creates a serialized representation of an array or an object.

Results:

Reference Address: http://www.w3school.com.cn/jquery/ajax_param.asp

To test the HTML:

<name= "Testform">    <name= " ID "  value=" 123 "/>    <name= "Age"  value= "/>"</form>

jquery form Serialization

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.