jQuery ajax() success, error VS .done(), .fail()
success and Error : A success callback that gets invoked upon successful completion of an Ajax request.
A failure callback that gets invoked in case there is any error while making the request.
Example:
$.ajax({
url: 'URL',
type: 'POST',
data: yourData,
datatype: 'json',
success: function (data) { successFunction(data); },
error: function (jqXHR, textStatus, errorThrown) { errorFunction(); }
});
.done() and .fail() :
.ajax().done(function(data, textStatus, jqXHR){}); Replaces method .success() which was deprecated in jQuery 1.8.This is an alternative construct for the success callback function above.
.ajax().fail(function(jqXHR, textStatus, errorThrown){}); Replaces method .error() which was deprecated in jQuery 1.8.This is an alternative construct for the complete callback function above.
$.ajax({
url: 'URL',
type: 'POST',
data: yourData,
datatype: 'json'
})
.done(function (data) { successFunction(data); })
.fail(function (jqXHR, textStatus, errorThrown) { serrorFunction(); });