Home >>jQuery Tutorial >jQuery $.post() Method
The $.post() method in jQuery is used to loads data from the server using a HTTP POST request.
Syntax:$(selector).post(URL,data,function(data,status,xhr),dataType)
Parameter | Description |
---|---|
URL | It is a Required parameter and is used to specifies the url to send the request to |
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(){
$.post("demo_test_post.asp",
{
name: "Phptpoint",
city: "Noida"
},
function(data,status){
alert("Data: " + data + "\nStatus: " + status);
});
});
});
</script>
</head>
<body>
<button class="btn1">Click me to Send an HTTP POST request</button>
</body>
</html>