jQuery.param()
The jQuery.param()
method in jQuery is used to create a serialized representation of an array, a plain object, or a jQuery object suitable for use in a URL query string or Ajax request.
jQuery.param()
syntaxjQuery.param(obj) jQuery.param(obj,traditional)
Parameter | Type | Description |
---|---|---|
obj |
Array,PlainObject,jQuery | data to be serialized for use in request or query string. |
traditional |
Boolean | whether to perform a traditional "shallow" serialization.Default false |
jQuery.param()
exampleSerialize a key/value object for URL query string
var myObject1 = { width:500, height:300 }; var str1 = jQuery.param( myObject1 ); // width=500&height=300 // Array of objects var myObject2 = [ { name: "name", value: "lautturi" }, { name: "age", value: "1" } ] var str2 = jQuery.param( myObject2 ); // name=lautturi&age=1 var myObject3 = { a: { one: 1, two: 2, three: 3 }, b: [ 1, 2, 3 ] }; var str3 = jQuery.param( myObject3,false ); // default // a%5Bone%5D=1&a%5Btwo%5D=2&a%5Bthree%5D=3&b%5B%5D=1&b%5B%5D=2&b%5B%5D=3 var str4 = jQuery.param( myObject3,true ); // a=%5Bobject%20Object%5D&b=1&b=2&b=3