Reputation: 1055
In the documentation for the .post() method, there's a callback function for when the request is successful, but is there a similar method to tell if the request was a failure?
Upvotes: 0
Views: 120
Reputation: 388316
The $.post() which is a utility function built on top of $.ajax() returns a promise object which has a fail handler that can used to handle failure cases
$.post(url, yourdata, function(){
//success handler
}).fail(function(){
//fail handler
}).done(function(){
//more success handlers if you want
})
Upvotes: 1
Reputation: 2281
Yes, use .fail
:
$.post("test.php", function(data) {
alert("Data Loaded: " + data);
})
.fail(function() {
alert("error");
})
Upvotes: 1