Table of Contents
The post() method in the jQuery is used to request data from the server with a post request. It is used to display the returned result from the requested webpage. In jQuery, that the post () method sends request along with some information using an HTTP POST request.
Syntax of .post()
(selector).post(URL,data,callback_function(data,status,xhr),dataType)
- The required parameter URL specifies the url you wish to request.
- Data parameter is optional, which can be used to send data to the server along with the request
- The parameter callback_function is an optional one that represents a function to be executed when the data is loaded successfully.
- Finally, DataType parameter is also optional one defines a type of data to be returnes to callback function.
Example Script using .post()
<script>
$(document).ready(function(){
$("button").click(function(){
$.post("demo_test_post.asp",
{
name: "Sophia",
city: "Hyderabad"
},
function(data,status){
alert("Data: " + data + "\nStatus: " + status);
});
});
});
</script>