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
traditionalboolean 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 to zip files?
- How do I create a jQuery Yes/No dialog?
- How can I use JQuery with Yii2?
- How do I use a jQuery zoom plugin?
- How do I use jQuery to zoom in or out on an element?
- How can I get the y position of an element using jQuery?
- How do I use jQuery with Yarn?
- How can I use jQuery to select elements with an XPath expression?
- How do I use jQuery ZTree to create a hierarchical tree structure?
- How can I prevent jQuery XSS vulnerabilities?
See more codes...