52,797
社区成员
发帖
与我相关
我的任务
分享
jQuery(function ($) {
//备份jquery的ajax方法
var _ajax = $.ajax;
//重写jquery的ajax方法
$.ajax = function (opt) {
//备份opt中error和success方法
var fn = {
error : function (XMLHttpRequest, textStatus, errorThrown) {},
success : function (data, textStatus) {
alert(1);
}
}
if (opt.error) {
fn.error = opt.error;
}
if (opt.success) {
fn.success = opt.success;
}
//扩展增强处理
var _opt = $.extend(opt, {
error : function (XMLHttpRequest, textStatus, errorThrown) {
//错误方法增强处理
fn.error(XMLHttpRequest, textStatus, errorThrown);
},
success : function (data, textStatus, xhr) {
//成功回调方法增强处理
fn.success(data, textStatus);
},
statusCode : { //传入statusCode对象,定义对状态码操作的方法
900 : function () { //900为服务器返回的自定义状态码,说明用户登录超时
alert("用户登录超时,请重新登录!");
window.location.href = "<%=path%>/login.jsp";
return;
},
901 : function () { //901为服务器返回的自定义状态码,说明当前操作没有权限
alert("用户无此操作权限,请联系管理员!");
//window.location.href= "<%=path%>/login.jsp";
return;
}
}
});
_ajax(_opt);
};
});