jQuery.param() JQ Home  <<  Ajax  <<  jQuery.param()

Serialized array/object representation.

Description

The jQuery.param() Ajax method, allows us to create a serialized representation of an array or object, suitable for use in a URL query string or Ajax request.

Shorthand version $.param()

  • The jQuery.param() method is used internally to convert form element values into a serialized string representation when using the .serialize() method.

Syntax

Signature Description
jQuery.param( object )Perform an asynchronous HTTP (Ajax) request to be sent to the specified url, optionally passing some request settings.
  • This signature serializes deep objects recursively and can be disabled globally by setting jQuery.ajaxSettings.traditional = true;.
jQuery.param( object, traditional )Perform an asynchronous HTTP (Ajax) request, optionally passing some request settings.

Parameters

Parameter Description Type
object An array or object to serialize. Array or
PlainObject
traditional A Boolean indicating whether to perform a traditional 'shallow' serialization.Boolean

Return

A String object.

jQuery.param( object ) Example Ajax  <<  Top

Create a serialized representation of an array or object, suitable for use in a URL query string or Ajax request.

In the example below when we press the button the first time we create a serialized representation of an object. For the example we output messages for this and also for the object decoded. The resultant string could just as easily be sent to a server as part of an Ajax request.




$(function(){
  $('#btn1').one('click', function(){
    var obj1 = {species: 'penguin', skills: {flight: 'no', swim: 'yes'}, climate: 'cold'};
    $('#div3').append($.param(obj1) + '<br />');
    $('#div3').append(decodeURIComponent($.param(obj1)) + '<br />');
    return false;
  });
;});


div3. Some initial text.



Press the button below to action the above code:

jQuery.param( object, traditional ) Example Ajax  <<  Top

Create a traditional 'shallow' serialized representation of an array or object, suitable for use in a URL query string or Ajax request.

In the example below when we press the button the first time we create a 'shallow' serialized representation of an object. For the example we output messages for this and also for the object decoded. The resultant string could just as easily be sent to a server as part of an Ajax request.




$(function(){
  $('#btn2').one('click', function(){
    var obj1 = {species: 'penguin', skills: {flight: 'no', swim: 'yes'}, climate: 'cold'};
    $('#div4').append($.param(obj1, true) + '<br />');
    $('#div4').append(decodeURIComponent($.param(obj1, true)) + '<br />');
    return false;
  });
});


div4. Some initial text.



Press the button below to action the above code:

Related Tutorials

jQuery Advanced Tutorials - Lesson 10 - Ajax Helper Functions