Easy Tutorial
❮ Event_Metakey Event One ❯

jQuery post() Method

jQuery AJAX Methods

Example 1

Load data from the server using an HTTP POST request:

$("button").click(function(){
    $.post("demo_test.html",function(data,status){
        alert("Data: " + data + "\nStatus: " + status);
    });
});

Example 2

Change the text of a <div> element using an AJAX POST request:

$("input").keyup(function(){
    txt=$("input").val();
    $.post("demo_ajax_gethint.html",{suggest:txt},function(result){
        $("span").html(result);
    });
});

Definition and Usage

The $.post() method loads data from the server using an HTTP POST request.


Syntax

Parameter Description
URL Required. Specifies the URL to which the request is sent.
data Optional. Specifies the data to be sent to the server along with the request.
function(data,status,xhr) Optional. Specifies a function to be run if the request succeeds. <br>Additional parameters: <br> data - Contains the result data from the request<br> <br>status - Contains the status of the request ("success", "notmodified", "error", "timeout", "parsererror")<br> <br>xhr - Contains the XMLHttpRequest object
dataType Optional. Specifies the type of data expected from the server response. <br>By default, jQuery performs smart detection. <br>Possible types: "xml" - An XML document<br> "html" - HTML as plain text<br> "text" - A plain text string<br> "script" - Runs the response as JavaScript and returns it as plain text<br> "json" - Runs the response as JSON and returns a JavaScript object<br> "jsonp" - Loads in a JSON block using JSONP, adds a "?callback=?" to the URL to specify the callback

jQuery AJAX Methods

❮ Event_Metakey Event One ❯