Description: Load data from the server using a HTTP POST request.
syntax:-
jQuery.post( url [, data ] [, success(data, textStatus, jqXHR) ] [, dataType ] ) $.ajax({ type: "POST", url: url, data: data, success: success, dataType: dataType }); $.post( "ajax/test.html", function( data ) { $( ".result" ).html( data ); }); $.post( "test.php", { name: "John", time: "2pm" } ); $.post( "test.php", { 'choices[]': [ "Jon", "Susan" ] } ); $.post( "test.php", $( "#testform" ).serialize() ); $.post( "test.php", function( data ) { alert( "Data Loaded: " + data ); }); $.post( "test.php", { name: "John", time: "2pm" }) .done(function( data ) { alert( "Data Loaded: " + data ); }); $.post( "test.php", { func: "getNameAndTime" }, function( data ) { console.log( data.name ); // John console.log( data.time ); // 2pm }, "json"); <script> // Attach a submit handler to the form $( "#searchForm" ).submit(function( event ) { // Stop form from submitting normally event.preventDefault(); // Get some values from elements on the page: var $form = $( this ), term = $form.find( "input[name='s']" ).val(), url = $form.attr( "action" ); // Send the data using post var posting = $.post( url, { s: term } ); // Put the results in a div posting.done(function( data ) { var content = $( data ).find( "#content" ); $( "#result" ).empty().append( content ); }); }); </script>
url
Type: String
A string containing the URL to which the request is sent.
data
Type: PlainObject or String
A plain object or string that is sent to the server with the request.
success(data, textStatus, jqXHR)
Type: Function()
A callback function that is executed if the request succeeds. Required if
dataType
is provided, but can be null
in that case.dataType
Type: String
The type of data expected from the server. Default: Intelligent Guess (xml, json, script, text, html).