Mohan R
What is the use of param() method in jQuery?

jQuery param() method is used to create a serialized representation of an object.

Syntax:

$.param(obj, val)
Find more jquery interview questions and answers

By Mohan R in JQuery on Dec 14 2020
  • Francisco Rodruiguez
    Sep, 2023 18

    In jQuery, the param() method is used to serialize an array or object of key-value pairs into a query string format that can be appended to a URL or used in an AJAX request. This method is particularly useful when you need to send data to a server using HTTP GET or POST requests, as it formats the data in a way that is commonly accepted by web servers.

    • 0
  • Yogeshkumar Hadiya
    Dec, 2020 30

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

    Example 1

    1. $(document).ready(function(){
    2. personObj = new Object();
    3. personObj.firstname = "yogesh";
    4. personObj.lastname = "hadiya";
    5. personObj.age = 21;
    6. $("button").click(function(){
    7. console.log($.param(personObj))
    8. });
    9. });

    if you run example 1 then you will find output like below :

    firstname=yogesh&lastname=hadiya&age=21

    Example 2

    1. $(document).ready(function(){
    2. personObj = new Object();
    3. personObj.firstname = "yogesh";
    4. personObj.lastname = "hadiya";
    5. personObj.age = 21;
    6. $("button").click(function(){
    7. console.log(personObj)
    8. });
    9. });

    if you run example 2 then you will find output like below :

    {firstname: “yogesh”, lastname: “hadiya”, age: 21}

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS