I found this topic (How to get response status code from jQuery.ajax?) in which it explain how to obtain the return the status, but I'm using $.post
which makes it a little different.
I have the following code:
$(function() {
$('#update_marker').submit( function(e) {
e.preventDefault();
$.post($("#update_marker").attr("action"), $("#update_marker").serialize(), function(data) {
if( $.trim(data).indexOf('<')==0 ) {
new Messi( lang['dist_general_error'], {title: 'Ops...', titleClass: 'anim error', buttons: [{id: 0, label: 'Fechar', val: 'X'}]});
} else {
var json = $.parseJSON( data );
if( json.status=="success" ) {
new Messi( json.msg );
} else {
new Messi( json.msg, {title: 'Ops..', titleClass: 'anim error', buttons: [{id: 0, label: 'Fechar', val: 'X'}]});
}
}
});
return false;
});
});
So I thought I'd change the $.post
call to something like
$.post($("#update_marker").attr("action"), $("#update_marker").serialize(), function(data, textStatus, jqXHR) {
and it DOES work if I get jqXHR.status
code = 200. But when the status = 500 I get nothing.
I'm trying to achieve this with minimal code changes as I have a lot of functions like this one, and I need to be able to capture the 500 code and treat in all of them.
Any ideas?