jQuery Tutorial Tutorials - jQuery jQuery.post()

jQuery 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 jQuery.post() syntax

jQuery.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 jQuery.post() example

example

Request the test.php page, specify a success handler to solve the data

$.post( "ajax/test.php", function( data ) {
  $( ".result" ).html( data );
});

example

Request the test.php page and send some additional data along (while still ignoring the return results).

$.post( "test.php", { name: "John", time: "2pm" } );

example

Alert the results from requesting test.php (HTML or XML, depending on what was returned).

$.post( "test.php", function( data ) {
  alert( "Data Loaded: " + data );
});

example

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 );
  });
Date:2019-08-30 03:01:25 From:www.Lautturi.com author:Lautturi