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