我在 ajax 设置中定义了一个错误回调,它将在每个 ajax 实例中执行:
$.ajaxSetup({
cache: false,
error: function (data, textStatus, pStatusDescription) {
if (pStatusDescription === "Unauthorized")
{
// show dialog
alert("Your Login has expired. Please re-login.");
return;
}
}
});
我还有一个简单的 ajax 请求,它有自己的错误处理定义。此定义覆盖 中的定义$.ajaxSetup
:
$.ajax({
url: "http://hostname",
success: function(xhr) { ... },
error: function(data, textStatus, pStatusDescription) {
if(pStatusDescription === "ObjectNotFound")
{
// remove Object
return;
}
// call 'error' callback in $.ajaxSetup now.
}
});
如何将错误从$.ajax
实例冒泡到$.ajaxSetup
?