Updated April 10, 2023
Definition of jQuery get query string parameter
The following article provides an outline of jQuery get query string parameter.
- The get query string parameter is a method to get data from URL requests.
- It is part of the Ajax event handler to display values of parameters.
- It is a function to display the part of the URL resources using an HTTP request. It provides the Ajax request method to get URL values from URL requests.
- The get query string parameter is an Ajax method to show values assign inside of the parameter.
- The get query string parameter is displayed serialized values of the URL query string.
- The get query string parameter is showing the array, a plain object of the URL query string using the param or get method.
- The get query string parameter is a method to get information from one page to another page.
Syntax:
This displays the values of the URL request. The query string parameter is part of the website-like HTML form. There are three ways to get the query string parameter of the URL. The first method is using the param() method using the jQuery selector.
$(" jQuery selector").text($.param(jQuery_Object));
The second method is using the get() method with the other URL link.
$.get("url", function( value ) {
Display string value of the parameter.
});
The third method is using serialize() method of the jQuery Ajax request.
$(jQuery selector).serialize();
How to get query string parameters in jQuery?
The HTML page is created through filename with .html extension.
Example: jQueryGetString.html
jQuery files are placed inside of the jQueryGetString.html file in the body section. To get the query string parameter the link needs to either download the jQuery library or use the jQuery CDN version link.
Download the latest development version or product version of jQuery from jQuery.com. The user can use offline jQuery in the web application through the jQuery library.
The jQuery version is placed inside of the HTML page. The jQuery link is below.
<script src = "https://ajax.googleapis.com/ajax/libs/jQuery/3.5.1/jQuery.min.js">
</script>
The user can use online jQuery in the web application through the jQuery CDN version link.
The <script> tag is placed inside of the body section on the HTML page.
<script> write a jQuery get query string parameter code here… </script>
<script>
$(document).ready(function(){
jQuery_Object = new Object();
jQuery_Object.tutorial = "online";
jQuery_Object.chapter = "jQuery";
jQuery_Object.topic = "methods";
$("button").click(function(){
$("h4").text($.param(jQuery_Object)).css("color","red");
});
});
</script>
• Use jQuery to get query string parameter syntax in the JQuery script tag.
$("h4").text($.param(jQuery_Object));
Write an HTML code in the body section of the web page.
<body>
<h2> JQuery get query string parameter </h2>
<button> click here... </button>
<h4></h4>
</body>
• Combine the working procedure with function.
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
jQuery_Object = new Object();
jQuery_Object.tutorial = "online";
jQuery_Object.chapter = "jQuery";
jQuery_Object.topic = "methods";
$("button").click(function(){
$("h4").text($.param(jQuery_Object)).css("color","red");
});
});
</script>
</head>
<body>
<h2> JQuery get query string parameter </h2>
<button> click here... </button>
<h4></h4>
</body>
</html>
Examples
Below are the different examples:
Example #1
A basic example is shown below.
Code:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
jQuery_Object = new Object();
jQuery_Object.tutorial = "online";
jQuery_Object.chapter = "jQuery";
jQuery_Object.topic = "methods";
$("button").click(function(){
$("h4").text($.param(jQuery_Object));
});
});
</script>
</head>
<body>
<h2> JQuery get query string parameter </h2>
<button> click here... </button>
<h4></h4>
</body>
</html>
Output:
Before clicking button
After clicking button
Example #2
The jQuery get query string parameter with style example.
Code:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
jQuery_Object = new Object();
jQuery_Object.tutorial = "online";
jQuery_Object.chapter = "jQuery";
jQuery_Object.topic = "methods";
$("button").click(function(){
$("h4").text($.param(jQuery_Object)).css("color","red");
});
});
</script>
</head>
<body>
<h2> JQuery get query string parameter </h2>
<button> click here... </button>
<h4></h4>
</body>
</html>
Output:
Before clicking button
After clicking button
Description:
You can see the above output of the example. You can add CSS style with the param() method.
You can get the string value by adding the style of the color, font size, and font style.
The jQuery string parameter does not include space between two strings.
Example #3
The jQuery get query string parameter with get() method.
Code:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<h2> JQuery get query string parameter </h2>
<button> Click Here... </button>
<p id = "jQuery"> </p>
<script>
$(document).ready(function() {
$("button").click(function() {
$.get("jQuery.html", function(data,status) {
document.getElementById("jQuery").innerHTML = data;
});
});
});
</script>
</body>
</html>
Output:
Before clicking button
After clicking button
Description:
You can see the above output of the example. You can use the get () method to get other web link’s value.
JQuery string parameter can include space between two strings.
Example #4
The jQuery get query string parameter with serialize () method.
Code:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("h4").text($("#jform").serialize());
});
});
</script>
</head>
<body>
<h2> JQuery get query string parameter </h2>
<form id = "jform">
User index: <input type="text" name="userIndex" value="jQuery_tutorial"><br><br>
tutorial: <input type="text" name="online" value="online_method">
</form>
<button> CLick here... </button>
<h4> </h4>
</body>
</html>
Output:
Before clicking button
After clicking button
Description:
You can see the above output of the example. You can use serialize method to get form value. JQuery string parameter does not include space between two strings.
Example #5: With string and a numerical value
Code:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
jQuery_Object = new Object();
jQuery_Object.tutorial = "online";
jQuery_Object.chapter = "jQuery";
jQuery_Object.students = 12;
jQuery_Object.hour = 5;
$("button").click(function(){
$("h4").text($.param(jQuery_Object)).css("color","green");
});
});
</script>
</head>
<body>
<h2> JQuery get query string parameter </h2>
<button> click here... </button>
<h4></h4>
</body>
</html>
Output:
Before clicking button
After clicking button
Description:
- You can see the above output of the example. You get the string and numerical value of the URL link.
- The jQuery string parameter does not include space between two strings. You must use a single string.
Conclusion
- It is used to get other URL request values with style.
- This function is used to get string values of the HTTP request.
- This function creates an elegant, user-friendly, and interactive web application.
Recommended Articles
This is a guide to jQuery get query string parameter. Here we discuss the Introduction, syntax, and examples with code implementation. You may also have a look at the following articles to learn more –