jQuery | get() Method

01 Mar, 2019
In jQuery .get() method loads data from the server by using the GET HTTP request. This method returns XMLHttpRequest object.
Syntax
$.get( url, [data], [callback], [type] )

Parameters
url : String containing the URL at which request is to be sentdata : This is an optional parameter that represents key/value pairs that will be sent to the server.callback: This optional parameter represents the function which is to be executed whenever the data is loaded successfully.type : This parameter represents type of data to be returned to the callback function i.e “xml”, “script”, “json”, “html”, “html”, “jsonp”, or “text”.
url : String containing the URL at which request is to be sent
data : This is an optional parameter that represents key/value pairs that will be sent to the server.
callback: This optional parameter represents the function which is to be executed whenever the data is loaded successfully.
type : This parameter represents type of data to be returned to the callback function i.e “xml”, “script”, “json”, “html”, “html”, “jsonp”, or “text”.
Example:
This PHP code is use to get data when below html program send the HTTP GET request.// Result.php file<?phpif( $_REQUEST["name"] ) {     $name = $_REQUEST['name'];   echo "Welcome ". $name;}  ?>
// Result.php file<?phpif( $_REQUEST["name"] ) {     $name = $_REQUEST['name'];   echo "Welcome ". $name;}  ?>
This HTML code is use to send the HTTP GET request.<html>  <head>    <script type="text/javascript"            src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">  </script>      <script type="text/javascript"            language="javascript">        $(document).ready(function() {          $("#driver").click(function(event) {                $.get(                 "result.php", {                     name: "GFG"                 },                 function(data) {                     $('#stage').html(data);                 });            });        });    </script></head>  <body>    <p>Click on the button to load result file   </p>      <span id="stage"           style="background-color:#cc0;">         GeeksForGeeks      </span>      <div>        <input type="button"               id="driver"               value="Load Data" />    </div>  </body>  </html>
<html>  <head>    <script type="text/javascript"            src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">  </script>      <script type="text/javascript"            language="javascript">        $(document).ready(function() {          $("#driver").click(function(event) {                $.get(                 "result.php", {                     name: "GFG"                 },                 function(data) {                     $('#stage').html(data);                 });            });        });    </script></head>  <body>    <p>Click on the button to load result file   </p>      <span id="stage"           style="background-color:#cc0;">         GeeksForGeeks      </span>      <div>        <input type="button"               id="driver"               value="Load Data" />    </div>  </body>  </html>
Output:Before clicking on the button:
After clicking on the button:
jQuery-Methods
Picked
JQuery
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
JQuery | Set the value of an input text field
How to change selected value of a drop-down list using jQuery?
Form validation using jQuery
How to add options to a select element using jQuery?
How to Dynamically Add/Remove Table Rows using jQuery ?
Installation of Node.js on Linux
Top 10 Projects For Beginners To Practice HTML and CSS Skills
Difference between var, let and const keywords in JavaScript
How to insert spaces/tabs in text using HTML/CSS?
How to fetch data from an API in ReactJS ?