When $.post succeeds, there is a success handler for it. What happens if it fails? Is there a similar handler that we can use for this case, so that we can inform the user that something is not happening right?
+1
A:
Why use jQuery for straight AJAX? Use the standard directly and bind to readystatechange
- then check for status
and work from there.
Delan Azabani
2010-05-17 04:24:56
+3
A:
There is not, according to the documentation, a specific error handler for $.post
method.
What you have to do, if you want to have both the success and fail handlers, is to use the low-level $.ajax
method. It's documentation can be found here: http://api.jquery.com/jQuery.ajax/
$.ajax({
type: "POST",
url: "some.php",
success: function(html){
/* Do success stuff here */
},
error: function(){
/* do error stuff here */
}
});
Alastair Pitts
2010-05-17 04:25:06
Thanks guys!!!!!! This is really useful!!!
Jux
2010-05-24 06:13:34
A:
You can catch it using .ajaxError(), but this applies to all ajax requests in your application. You also need to make sure you send back a HTTP error status back to the front end to be captured by jQuery.
jpartogi
2010-05-17 04:28:44