下面的技术工作了我...我知道这是为时已晚,但希望代码将帮助某人
1)检查会话超时在控制器(MVC),并返回其应在客户端
if (!Request.IsAuthenticated)
{
return new HttpStatusCodeResult((HttpStatusCode)302, "Authentication timeout");
}
2)在客户端使用jQuery全局AJAX错误,它可以捕获来自所有Ajax调用的错误处理的 状态代码。检查状态代码并重定向到登录页面
$(document).ajaxError(function (event, jqxhr, settings, thrownError) {
if (jqxhr.status === 302) {
document.location.href = '/account/login';
}
});
3)[可选]禁用从数据表上的警告和检查控制台
/*disable datatable warnings*/
$.fn.dataTable.ext.errMode = 'none';
/*display warnings in the console*/
$tblDashboard.on('error.dt', function (e, settings, techNote, message) {
console.log('An error has been reported by DataTables: ', message);
});
这是正确的;只需定义一个'error'回调。 –