jQuery.post()The jQuery.post() method in jQuery is used to load data from the server using a HTTP POST request.
It's a shorthand Ajax function, which is equivalent to:
$.ajax({
type: "POST",
url: url,
data: data,
success: success,
dataType: dataType
});
jQuery.post() syntaxjQuery.post( url [, data ] [, success ] [, dataType ] ) jQuery.post( [settings] )
| Parameter | Type | Description |
|---|---|---|
url |
String | request url |
data |
PlainObject,String | The data sent to the server |
success |
Function | callback function that is executed if the request succeeds. |
dataType |
String | xml, json, script, text, html(Default: Intelligent Guess ) |
settings |
PlainObject | A set of key/value pairs that configure the Ajax request. |
jQuery.post() exampleRequest the test.php page, specify a success handler to solve the data
$.post( "ajax/test.php", function( data ) {
$( ".result" ).html( data );
});
Request the test.php page and send some additional data along (while still ignoring the return results).
$.post( "test.php", { name: "John", time: "2pm" } );
Alert the results from requesting test.php (HTML or XML, depending on what was returned).
$.post( "test.php", function( data ) {
alert( "Data Loaded: " + data );
});
Alert the results from requesting test.cgi with an additional payload of data (HTML or XML, depending on what was returned).
$.post( "test.cgi", { name: "John", time: "2pm" } )
.done(function( data ) {
alert( "Data Loaded: " + data );
});
