ajaxRedirect.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /**
  2. * 给所有的ajax 添加监控 并处理
  3. *
  4. */
  5. jQuery(function($){
  6. // 备份jquery的ajax方法
  7. var _ajax=$.ajax;
  8. // 重写ajax方法,先判断登录在执行success函数
  9. $.ajax=function(opt){
  10. var _success = opt && opt.success || function(a, b){};
  11. var _opt = $.extend(opt, {
  12. success:function(data, textStatus){
  13. if(data.errorUrl) location.href=data.errorUrl;
  14. else
  15. _success(data, textStatus);
  16. }
  17. });
  18. _ajax(_opt);
  19. };
  20. $.ajax({
  21. url: baseConfig.URL.loginInfo + "",
  22. type: "get",
  23. data:{},
  24. cache: false,
  25. success:function (res) {
  26. console.log(res);
  27. },
  28. complete:function (XHR, TS) {
  29. // $('.ui-dialog-buttonpane').find('button:contains("保存添加信息")').removeAttr("disabled");
  30. },
  31. error:function (XMLHttpRequest, textStatus, errorThrown) {
  32. // alert(textStatus);
  33. }
  34. });
  35. });