I have the following function in my code:
$.post($form.attr('action'), $form.serializeArray())
.done(function (json) {
}
From what I understand from the jQuery docs this is a shortcut. What I would like to do is to change so that it allows me to have some function that executes on success and some function that executes on error. Is this possible to do? All I see is a .done?
$.ajax({
url: target,
dataType: 'json',
type: 'POST',
data: data,
success: function(data, textStatus, XMLHttpRequest) { },
error: function(XMLHttpRequest, textStatus, errorThrown) { }
Since all the jQuery ajax methods, including $.post(), return a jqXHR object, you can use the Deferred object API if you don't want to use a full-out $.ajax() call.
$.post(/* snip */).fail(function () {/* snip */});
Actually you can use .success() .error() and .complete() as chained methods to .post() - http://api.jquery.com/jQuery.post/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With