JQuery Ajax

August 6, 2017
Basic template

$.ajax({
  method: "POST",
  url: "some.php",
  data: { name: "John", location: "Boston" }
})
.done(function(data, textStatus, jqXHR) {
  alert( "success" );
})
.fail(function(jqXHR, textStatus, errorThrown) {
  alert( "error" );
})
.always(function(data_or_jqXHR, textStatus, jqXHR_or_errorThrown) {
  alert( "complete" );
});
Assign handlers immediately after making the request, and stores the jqXHR object for this request on a variable

var jqxhr = $.ajax( "example.php" )
.done(function() {
  alert( "success" );
})
.fail(function() {
  alert( "error" );
})
.always(function() {
  alert( "complete" );
});
Set another completion function for the request above

jqxhr.always(function() {
  alert( "second complete" );
});