jQuery param() method is used to create a serialized representation of an object.
Syntax:
$.param(obj, val)Find more jquery interview questions and answers
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.
The param() method creates a serialized representation of an array or an object.
Example 1
$(document).ready(function(){ personObj = new Object(); personObj.firstname = "yogesh"; personObj.lastname = "hadiya"; personObj.age = 21; $("button").click(function(){ console.log($.param(personObj)) });});
$(document).ready(function(){
personObj = new Object();
personObj.firstname = "yogesh";
personObj.lastname = "hadiya";
personObj.age = 21;
$("button").click(function(){
console.log($.param(personObj))
});
if you run example 1 then you will find output like below :
firstname=yogesh&lastname=hadiya&age=21
Example 2
$(document).ready(function(){ personObj = new Object(); personObj.firstname = "yogesh"; personObj.lastname = "hadiya"; personObj.age = 21; $("button").click(function(){ console.log(personObj) });});
console.log(personObj)
if you run example 2 then you will find output like below :
{firstname: “yogesh”, lastname: “hadiya”, age: 21}