Home >>jQuery Tutorial >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 | 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:
|
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:
|
<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>