1$(function(){
2 $('#myForm').on('submit', function(e){
3 e.preventDefault();
4 $.post('http://www.somewhere.com/path/to/post',
5 $('#myForm').serialize(),
6 function(data, status, xhr){
7 // do something here with response;
8 });
9 });
10});
11
1$.post( "ajax/test.html", function( data ) {
2 $( ".result" ).html( data );
3});
4
1// Assign handlers immediately after making the request,
2// and remember the jqxhr object for this request
3var jqxhr = $.post( "example.php", function() {
4 alert( "success" );
5})
6 .done(function() {
7 alert( "second success" );
8 })
9 .fail(function() {
10 alert( "error" );
11 })
12 .always(function() {
13 alert( "finished" );
14 });
15
16// Perform other work here ...
17
18// Set another completion function for the request above
19jqxhr.always(function() {
20 alert( "second finished" );
21});
22