Home >>jQuery Tutorial >jQuery $.get() Method

jQuery $.get() Method

jQuery $.get() Method

jQuery $.get() method in jQuery is used to loads data from the server using a HTTP GET request.

Syntax:
$.get(URL,data,function(data,status,xhr),dataType)

Parameter Values

Parameter Description
URL It is a Required parameter and is used to specifies the URL you wish to request
data It is an Optional parameter and is used to specifies data to send to the server along with the request
function(data,status,xhr) It is an Optional parameter and is used to specifies a function to run if the request succeeds
Additional parameters:
  • data – It is used to contains the resulting data from the request
  • status – It is used to contains the status of the request ("success", "notmodified", "error", "timeout", or "parsererror")
  • xhr – It is used to contains the XMLHttpRequest object
dataType It is an Optional parameter and is used to specifies the data type expected of the server response.
By default jQuery performs an automatic guess.
Possible types:
  • "xml" – it is an an XML document
  • "html" – It is a HTML as plain text
  • "text" – It is used as a plain text string
  • "script" – It is used to Runs the response as JavaScript, and returns it as plain text
  • "json" – It is used to Runs the response as JSON, and returns a JavaScript object
  • jsonp" – It is used to Loads in a JSON block using JSONP. Will add an "?callback=?" to the URL to specify the callback
Here is an Example of jQuery get() Method:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".btn1").click(function(){
$.get("demo_test.asp", function(data, status){
alert("Data: " + data + "\nStatus: " + status);
});
});
});
</script>
</head>
<body>
<button class="btn1">Click Me to Send an HTTP GET request </button>
</body>
</html>

Output:

No Sidebar ads