jqueryHow do I use jQuery to set query parameters?
Using jQuery, query parameters can be set with the .param()
method. This method takes one or more key/value pairs and returns a URL-encoded string.
Example
var params = {
name: 'John',
age: 30
};
var queryString = $.param(params);
console.log(queryString);
// Output: name=John&age=30
The .param()
method takes two arguments:
- An object containing key/value pairs that will be encoded into the query string.
- An optional
traditional
boolean parameter that, when set totrue
, will use traditional (shallow) serialization.
The .param()
method can also be used to retrieve the query string from a URL:
var queryString = 'name=John&age=30';
var params = $.param(queryString);
console.log(params);
// Output: {name: 'John', age: '30'}
Helpful links
More of Jquery
- How do I use jQuery ZTree to create a hierarchical tree structure?
- How do I use jQuery to zoom in or out on an element?
- How do I use jQuery to zip files?
- How do I use jQuery to zoom in on an image?
- How do I use jQuery to detect window resize events?
- How do I use jQuery UI draggable?
- How do I get the y-position of an element using jQuery?
- How can I use jQuery to zoom an image when the user hovers over it?
- How can I convert XML data to JSON using jQuery?
- How do I change the background color using jQuery?
See more codes...