这取决于什么都可以发生在你的控制器上。
如果你有绝对的把握不可能有任何404错误或不会有任何超时错误,你可以没有错误处理功能工作。但是因为我确定你不能说100%肯定,所以我会说你必须实现它)
但是,这里是我的提示:如果你多次使用AJAX调用,创建你自己的“AJAX API”,它仅使用一个回调,您可以使用一个状态参数告诉回调是否一切正常与否,所以实际上你只需要使用一个if-else语句。
这是我的方法来处理一个PHP后端一个简单的例子:
ajax = function (callback) {
$.ajax({
// whatever you need here
success: function (response) {
if (typeof callback == "function") {
callback(true, response);
}
},
error: function (e) {
if (typeof callback == "function") {
if (e.statusText == "timeout") {
callback(false, {"timeout": true})
} else {
try {
JSON.parse(e.responseText)
// if try is successfull, there is no fatal-error (which would exit the PHP, so no JSON)
callback(false, {})
} catch (x) {
// only maximum-execution-time-errors are fatal errors :P
if (e.responseText.indexOf('Fatal error') != -1) {
callback(false, {"timeout": true})
}
}
}
}
},
})
}