error handling with .post()

Define the error callback immediately after the post. Note the semi-colon placement only at the end.

$.post('balbal.html', json, function(data) {
    // ... my code ...
})
.fail(function(response) {
    alert('Error: ' + response.responseText);
});

http://api.jquery.com/deferred.fail/

For older versions of jQuery (pre-1.8) Use .error instead with the same syntax.

Leave a Comment