JQuery post function extension

My code has the following function:

        $.post($form.attr('action'), $form.serializeArray())
            .done(function (json) {
            }

From what I understand from jQuery docs, this is a shortcut. What I would like to do is change so that it allows me to execute some function that executes on successful execution, and some function that executes on error. Is it possible to do this? All I see is .done?

$.ajax({
   url: target,
   dataType: 'json',
   type: 'POST',
   data: data,
   success: function(data, textStatus, XMLHttpRequest) { },
   error: function(XMLHttpRequest, textStatus, errorThrown) { }
+3
source share
2 answers

Since all jQuery ajax methods , including $.post(), return jqXHR, you can use the deferred object API if you do not want to use a fully functional $.ajax()call.

$.post(/* snip */).fail(function () {/* snip */});
+6
source

.success().error() .complete() .post() - http://api.jquery.com/jQuery.post/

+2

All Articles