Насколько я понимаю, одной из возможностей обработки результатов ошибок с помощью ajax является следующая:
$.ajax({
url: someUrl,
type: 'POST',
success: function(data) {},
error: function(jqXHR, exception) {
if (jqXHR.status === 0) {
alert('Not connect.\n Verify Network.');
} else if (jqXHR.status == 404) {
alert('Requested page not found. [404]');
} else if (jqXHR.status == 500) {
alert('Internal Server Error [500].');
} else if (exception === 'parsererror') {
alert('Requested JSON parse failed.');
} else if (exception === 'timeout') {
alert('Time out error.');
} else if (exception === 'abort') {
alert('Ajax request aborted.');
} else {
alert('Uncaught Error.\n' + jqXHR.responseText);
}
}
});
Или используйте statusCode
, чтобы сделать его более читабельным:
$.ajax({
url: someUrl,
type: 'POST',
statusCode: {
200: function(data) {
:
:
},
401: function() {
:
:
},
:
:
Мой вопрос:
Возможно ли использовать statusCode
и иметь для него обход по умолчанию?