The Wayback Machine - https://web.archive.org/web/20240616033437/https://www.geeksforgeeks.org/jquery-post-method/
Open In App

jQuery | post() Method

Last Updated : 01 Mar, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

The post() method in jQuery loads the page from server using POST HTTP request and returns XMLHttpRequest object.

Syntax:

 $.post( url, data, callback_function, data_type )

Parameters: This method accepts four parameters as mentioned above and described below:

  • url: It is the required parameter and used to send the request.
  • data: It is optional parameter and it represents key/value pairs of data that will be sent to the server.
  • callback_function: It is optional parameter and it represents a function to be executed when the data is loaded successfully.
  • data_type: It is optional parameter and it represents a type of data to be returned to callback function: xml, html, script, json, jsonp, or text.

main.php This PHP file call in the below example when button pressed.




<?php
    echo "Hello Geeks!";
?>


Example: This example use post() method and call a PHP file.




<!DOCTYPE html>
<html>
      
<head>
    <title>
        jQuery post() Method
    </title>
      
    <script src=
    </script>
</head>
  
<body>
    <h2 id="gfg">GeeksforGeeks</h2> 
      
    <button id="b">
        Click Here!
    </button> 
      
    <!-- Script to use post() method -->
    <script>
        $(document).ready(function() {
            $("button").click(function() {
                $.post("/submit.php", {
                    name: "GFG",
                },
                  
                function(data,status) {
                    document.getElementById("gfg").innerHTML
                            = data;
                    document.getElementById("b").innerHTML
                            = "Data Passed";
                });
            });
        });
    </script>
</body>
  
</html>


Output:
Before clicking on the button:

After clicking on the button:



Previous Article
Next Article

Similar Reads

How to get form data using POST method in PHP ?
PHP provides a way to read raw POST data of an HTML Form using php:// which is used for accessing PHP’s input and output streams. In this article, we will use the mentioned way in three different ways. We will use php://input, which is a read-only PHP stream. We will create a basic HTML form page where we can use all the possible approaches one at
2 min read
Simple GET and POST request using Fetch API method by making custom HTTP library
The fetch() method is used to send the requests to the server without refreshing the page. It is an alternative to the XMLHttpRequest object. We will be taking a dummy API that will contain an array of array as an example and we will show GET and POST data by Fetch API method by making custom HTTP library. Used API: https://jsonplaceholder.typicode
3 min read
How to get information sent via post method in PHP ?
In this article, we will learn to get information via the post method in PHP. In PHP, we can use the $_POST method as a superglobal variable that is operated to manage form data. After we click on submit button and the page will send the data through the post method. We can use the data after storing it in a variable according to our requirements.
2 min read
How to test POST Method of Express with Postman?
The POST method is a crucial aspect of web development, allowing clients to send data to the server for processing. In the context of Express, a popular web framework for Node, using the POST method involves setting up routes to handle incoming data. In this article, we'll explore how to test the POST method of Express with Postman. Prerequisites:B
2 min read
Get and Post method using Fetch API
The fetch() method is used to send the requests to the server without refreshing the page. It is an alternative to the XMLHttpRequest object.The basic syntax of a fetch() request is as follows: C/C++ Code fetch(url, {options}) .then(data =&gt; { // Do some stuff here }) .catch(err =&gt; { // Catch and display errors }) The difference between XMLHtt
3 min read
Mongoose Query.prototype.post() API
The Mongoose Query API post() method is used to add a post middleware to the mongoose query instance, which can be used in performing post-query operations. Syntax: Query.prototype.post(fn) Parameters: It accepts the following parameters as mentioned above and described below: fn: It is a middleware function that is used to perform post-query opera
2 min read
HTTP GET and POST Methods in PHP
In this article, we will know what HTTP GET and POST methods are in PHP, how to implement these HTTP methods &amp; their usage, by understanding them through the examples. HTTP: The Hypertext Transfer Protocol (HTTP) is designed to enable communications between clients and servers. HTTP works as a request-response protocol between a client and serv
4 min read
How to auto like all the comments on a facebook post using JavaScript ?
In this article, we are going to learn how to like all the comments on a Facebook post automatically. Many times we want to like all the comments of friends on our post or on any other's post, so this script helps us to save time and effort by automatically liking all the comments on the post. Approach: Make variable comments that points to an arra
2 min read
How to receive JSON POST with PHP ?
In this article, we will see how to retrieve the JSON POST with PHP, &amp; will also see their implementation through the examples. First, we will look for the below 3 features: php://input: This is a read-only stream that allows us to read raw data from the request body. It returns all the raw data after the HTTP headers of the request, regardless
2 min read
Two most misunderstood terms GET and POST in web development
If you have done any kind of web development then you must have come across these two terms GET &amp; POST. These terms are introduced with respect to the form tag. The explanation was like this: “In the form tag, there is an attribute called method. There you can specify in which way you want to send data to the backend. There are two values prese
7 min read