--- title: jQuery Ajax Post Method --- ## jQuery Ajax Post Method Sends an asynchronous http POST request to load data from the server. Its general form is: ```javascript jQuery.post( url [, data ] [, success ] [, dataType ] ) ``` * url : is the only mandatory parameter. This string contains the adress to which to send the request. The returned data will be ignored if no other parameter is specified * data : A plain object or string that is sent to the server with the request. * success : A callback function that is executed if the request succeeds.it takes as an argument the returned data. It is also passed the text status of the response. * dataType : The type of data expected from the server. The default is Intelligent Guess (xml, json, script, text, html). if this parameter is provided, then the success callback must be provided as well. #### Examples ```javascript $.post('http://example.com/form.php', {category:'client', type:'premium'}); ``` requests `form.php` from the server, sending additional data and ignoring the returned result ```javascript $.post('http://example.com/form.php', {category:'client', type:'premium'}, function(response){ alert("success"); $("#mypar").html(response.amount); }); ``` requests `form.php` from the server, sending additional data and handling the returned response (json format). This example can be written in this format: ```javascript $.post('http://example.com/form.php', {category:'client', type:'premium'}).done(function(response){ alert("success"); $("#mypar").html(response.amount); }); ``` The following example posts a form using Ajax and put results in a div ``` html jQuery.post demo
``` The following example use the github api to fetch the list of repositories of a user using jQuery.ajax() and put results in a div ``` html jQuery Get demo
``` ### jQuery.ajax() `$.post( url [, data ] [, success ] [, dataType ] )` is a shorthand Ajax function, equivalent to: ```javascript $.ajax({ type: "POST", url: url, data: data, success: success, dataType: dataType }); ``` `$.ajax()` provides way more options that can be found here #### More Information: For more information, please visit the official website