Red Red - 1 year ago 48
Ajax Question

How to determine error if using $.post() or $.get()

I would like to know how to handle errors for
$.post or $.get


without using $.ajax which has an error handler.

url: url,
type: $(this).attr("method"),
dataType: "JSON",
data: data,
processData: false,
contentType: false,
success: function (data, status)

error: function (xhr, desc, err)


Answer Source

jQuery's post and get are promisses, so you can chain the functions done, fail and always on these:

var jqxhr = $.post( "example.php", function() {
.done(function() {
    alert("second success");
.fail(function() {
.always(function() {

Or even later, by a varibale:

jqxhr.always(function() {
    alert("second finished");

See the documentation.