拦截$.ajax方法实现登录过期登录

时间:2023-03-08 21:57:28
 jQuery(function ($) {

    var CreateLoginWindows = function (callback) {
var h = 300;
$('#CreateLoginWindowsDlg').dialog({
width: 500,
height: h,
modal: true,
title: "系统登录"
}); var urlStr = LoginWindowsPage;
$('#CreateLoginWindowsDlg').empty();
$('#CreateLoginWindowsDlg').append("<iframe style='width:98%;height:98%;border:0px;' src='" + urlStr + "'></iframe>");
var top = $(document).scrollTop() + ($(window).height() - h) * 0.5;
$('#CreateLoginWindowsDlg').window('open').window('resize', { top: top });
}; // 备份jquery的ajax方法
var _ajax = $.ajax;
// 重写ajax方法,先判断登录在执行success函数
$.ajax = function (opt) {
var _success = opt && opt.success || function (a, b) { };
var _opt = $.extend(opt, {
success: function (data, textStatus) {
if (data.Message == "请重新登录") {//要求登陆
CreateLoginWindows();
return false;
}
_success(data, textStatus);
}
});
_ajax(_opt);
};
});