2
在我的MVC頁面佈局我有以下幾點:手柄的jQuery Ajax錯誤
$("body").ajaxError(
function (e, request) {
if (request.status == 403 || request.status == 500) {
window.location = '@Url.Action("LogOn", "Account", new {area = "", msg = "forbidden", returnUrl = HttpContext.Current.Request.RawUrl})' + window.location.hash;
return;
}
window.location = '@Url.Action("Index", "Error")';
}
);
另一頁上,我像這樣進行Ajax調用:
...
$.when(refreshActionLinks(row, machineId, packageId)).done(function(a1) {
row.find("span").text(opStatus).removeClass("pending");
progressbar.progressbar("destroy");
$(row).flash(bg[1], 1000);
});
...
javascript函數:
function refreshActionLinks($row, machineId, packageId) {
try {
var json = JSON.stringify({ packageId: packageId, machineId: machineId, tabType: $("#TabType").val() });
console.log("refreshActionLinks => " + json);
$row.find("td.options div.actionLinks").html("<img src='@Url.Content("~/Content/images/ajax-load2.gif")' />"); // pending
return $.ajax({
url: "@Url.Action("GetActionLinks", "Packages")",
data: json,
timeout: 50000,
contentType: 'application/json',
type: 'POST',
success: function (data) {
if ($row.length) {
$row.find("td.options div.actionLinks").html(data);
}
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(textStatus, errorThrown);
}
});
} catch(e) {
// hide icons
$row.find("a.action").remove();
}
}
問題是,雖然refreshAction函數正在執行,但單擊菜單鏈接會導致ajax調用錯誤 - 這是在這種情況下是正確的。但它確實帶我到/索引/錯誤頁面,這是不正確的。我想要「$(」body「)。ajaxError」來處理網站上的所有ajax錯誤,除了我調用refreshActionLinks的頁面外。注意,我已經有了圍繞我的ajax調用的try/catch。爲什麼不工作?
感謝