扩展jquery的ajax,实现登录超时和权限提示
来源:互联网 发布:端口费用是什么意思 编辑:程序博客网 时间:2024/05/22 12:31
//扩展ajax方法,用来统一处理后端抛出的异常 (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){}, complete:function(XMLHttpRequest, textStatus){}, beforeSend : function(XMLHttpRequest){} }; if(opt.error){ fn.error=opt.error; } if(opt.success){ fn.success=opt.success; } if(opt.beforeSend){ fn.beforeSend=opt.beforeSend; } if(opt.complete){ fn.complete=opt.complete; } // //扩展增强处理 var _opt = $.extend(opt, { error: function (xhr,textStatus,errorThrown) { var msg = xhr.responseText; if(typeof msg == 'string') { if (startWith(msg, "<timeout></timeout>")) { $.alert({content:"登录超时,请重新登录!",confirm: function () { location.href='/cpams/login_achieve/login'; }}); return; } else if (startWith(msg, "<nopower></nopower>")) { $.alert("对不起,您没有操作权限!<br>"+msg.substring(19,msg.length)); return; } } fn.error(xhr, textStatus, errorThrown); }, success: function (data, textStatus) { if(data.hasOwnProperty("code") && -1 == data.code){//异常的统一处理 $.alert(data.message); return; } //成功回调方法增强处理 if(typeof data == 'string'){ if (startWith(data, "<timeout></timeout>")) { $.alert({content:"登录超时,请重新登录!",confirm: function () { location.href='/cpams/login_achieve/login'; }}); return; } else if (startWith(data, "<nopower></nopower>")) { $.alert("对不起,您没有操作权限!<br>"+data.substring(19,data.length)); return; }} fn.success(data, textStatus); }, beforeSend: function (XHR,obj) { //提交前回调方法 $("#home_loading").show(); fn.beforeSend(XHR,obj); }, complete: function (XHR, TS) { //请求完成后回调函数 (请求成功或失败之后均调用)。 $("#home_loading").hide(); fn.complete(XHR, TS); } }); return _ajax(_opt); }; })(jQuery);
阅读全文
0 0
- 扩展jquery的ajax,实现登录超时和权限提示
- jquery ajax 加载超时提示
- jquery ajax 加载超时提示
- struts2+jquery ajax提交登录超时验证
- jQuery-Ajax用户登录功能的实现
- .php会员登录权限和超时退出
- jquery的ajax扩展
- jquery实现ajax验证登录
- JQuery+Ajax实现登录验证
- jQuery+Ajax实现用户登录
- Jquery注意事项(扩展和ajax)
- jQuery 实现提示信息或登录提示
- 使用 Perl、jQuery、Ajax、JSON 和 MySQL 实现简单的登录
- JQuery_JAVA_利用jQuery的AJAX和JSON实现可输入下拉框提示
- 利用jquery Ajax和.Net IHttpAsyncHandler实现网站的即时提示
- 利用jquery Ajax和.Net IHttpAsyncHandler实现网站的即时提示
- 为jQuery的$.ajax设置超时时间
- jquery的ajax实现登录名的校验
- Java面试题
- Noi2015 程序自动分析
- C++强制类型转换_0
- 1020. 月饼 (25)
- linux里挂载(mount)和取消挂载(umount)命令的使用
- 扩展jquery的ajax,实现登录超时和权限提示
- 安装的js提示插件
- 光盘yum源搭建步骤
- bzoj2251 [2010Beijing WC]外星联络(后缀数组+暴力)
- 1023. 组个最小数 (20)
- Metasploit渗透测试 学习路线
- sublime text3实用教程-安装js智能提示插件
- 17年 | 重开blog | 关于对称网络的的一点想(kun)法(huo)
- Spring笔记04-Spring加载Bean