Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • jQuery.param() method in jQuery

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 146
    Comment on it

    jQuery.param()

    Syntax:

    $.param(object,traditional)

    object: object parameter in param method is an array, a plain object, or a jQuery object which needs to be  serialized.

    traditional: This parameter is a boolean indicating whether a traditional "shallow" serialization is to be performed.

    Advantage of using jQuery.param() method is it creates a serialized representation of an array,an object or a jQuery object thus returning a string. When a jQuery object is passed, it should contain input elements with name/value properties. The serialized values then can be used in the URL query string when making an AJAX request.

    Program using param() method:

    <!DOCTYPE html>
    <html>
    <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
    <script>
    $(document).ready(function(){
       var myObject = {
        a: {one: 1,two: 2,three: 3},
        b: [1, 2, 3]}; 
        var a = $.param(myObject);
        var b = decodeURIComponent($.param(myObject));
        $("#btn1").click(function(){
          alert(a);
        });
        $("#btn").click(function(){
           alert(b);
        });
    });
    </script>
    </head>
    <body>
    
    <button id="btn1">Serialize object</button>
    <button id="btn">DeSerialize object</button>
    
    
    <div></div>
    
    </body>
    </html>
    

    In the program above 2 buttons are created on click of first button serialized data is alerted using param() method while clicking on second button the same data is deserialized using decodeURIComponent.The conversion of the passed object into a stream of data so that it can be easily transmittable over the network is done by the The param() method. The serialized data converted by param() method can be defined as a linear stream of data that which are useful to be passed across process boundaries and machines.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: