Open In App
Related Articles

jQuery | post() Method

Improve Article
Save Article
Like Article

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


 $.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.

    echo "Hello Geeks!";

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

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

Before clicking on the button:

After clicking on the button:

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 01 Mar, 2019
Like Article
Save Article
Similar Reads
Complete Tutorials