Pārlūkot izejas kodu

ajax异常统一处理

git-svn-id: https://192.168.57.71/svn/jsgkj@1235 931142cf-59ea-a443-aa0e-51397b428577
ld_zhouk 8 gadi atpakaļ
vecāks
revīzija
2fe1a1256c

+ 3 - 3
gkaqv2/trunk/modules/web/src/main/java/com/xt/js/gkaq/common/log/aspect/SysLogAspect.java → gkaqv2/trunk/modules/web/src/main/java/com/xt/js/gkaq/web/common/log/aspect/SysLogAspect.java

@@ -1,4 +1,4 @@
-package com.xt.js.gkaq.common.log.aspect;
+package com.xt.js.gkaq.web.common.log.aspect;
 
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
@@ -31,10 +31,10 @@ import org.springframework.web.context.request.ServletRequestAttributes;
 import com.xt.js.gkaq.common.Constants;
 import com.xt.js.gkaq.common.ex.BusinessException;
 import com.xt.js.gkaq.common.log.annotation.SysLog;
-import com.xt.js.gkaq.common.util.DateUtil;
-import com.xt.js.gkaq.common.util.IpUtil;
 import com.xt.js.gkaq.frame.model.SysLogModel;
 import com.xt.js.gkaq.frame.service.SysLogService;
+import com.xt.js.gkaq.web.common.util.DateUtil;
+import com.xt.js.gkaq.web.common.util.IpUtil;
 
 /**
  * ÈÕÖ¾¹ÜÀíÇеãÀà

+ 1 - 1
gkaqv2/trunk/modules/web/src/main/java/com/xt/js/gkaq/common/util/CustomDateSerializer.java → gkaqv2/trunk/modules/web/src/main/java/com/xt/js/gkaq/web/common/util/CustomDateSerializer.java

@@ -1,4 +1,4 @@
-package com.xt.js.gkaq.common.util;
+package com.xt.js.gkaq.web.common.util;
 
 import java.io.IOException;
 import java.text.SimpleDateFormat;

+ 1 - 1
gkaqv2/trunk/modules/web/src/main/java/com/xt/js/gkaq/common/util/DateUtil.java → gkaqv2/trunk/modules/web/src/main/java/com/xt/js/gkaq/web/common/util/DateUtil.java

@@ -1,4 +1,4 @@
-package com.xt.js.gkaq.common.util;
+package com.xt.js.gkaq.web.common.util;
 
 import java.text.ParseException;
 import java.text.SimpleDateFormat;

+ 1 - 1
gkaqv2/trunk/modules/web/src/main/java/com/xt/js/gkaq/common/util/IpUtil.java → gkaqv2/trunk/modules/web/src/main/java/com/xt/js/gkaq/web/common/util/IpUtil.java

@@ -1,4 +1,4 @@
-package com.xt.js.gkaq.common.util;
+package com.xt.js.gkaq.web.common.util;
 
 import java.net.InetAddress;
 import java.net.UnknownHostException;

+ 1 - 1
gkaqv2/trunk/modules/web/src/main/java/com/xt/js/gkaq/common/util/UserSessionListener.java → gkaqv2/trunk/modules/web/src/main/java/com/xt/js/gkaq/web/common/util/UserSessionListener.java

@@ -1,4 +1,4 @@
-package com.xt.js.gkaq.common.util;
+package com.xt.js.gkaq.web.common.util;
 
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;

+ 1 - 1
gkaqv2/trunk/modules/web/src/main/java/com/xt/js/gkaq/web/vo/UserVo.java

@@ -6,7 +6,7 @@ import org.springframework.format.annotation.DateTimeFormat;
 
 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 import com.xt.js.gkaq.common.BaseVo;
-import com.xt.js.gkaq.common.util.CustomDateSerializer;
+import com.xt.js.gkaq.web.common.util.CustomDateSerializer;
 
 public class UserVo extends BaseVo {
     private String id;

+ 1 - 1
gkaqv2/trunk/modules/web/src/main/resources/spring/spring.xml

@@ -24,7 +24,7 @@
 		ignore-resource-not-found="true" location="classpath*:spring/application.properties" />
 	<!-- 开启注解配置 -->
 	<!-- 使用annotation 自动注册bean, 并保证@Required、@Autowired的属性被注入. @Controller的Bean注入在spring-mvc.xml中自动注册 -->
-	<context:component-scan base-package="com.xt.js.gkaq.common.log.aspect"/>
+	<context:component-scan base-package="com.xt.js.gkaq.web.common.log.aspect"/>
 	<context:component-scan base-package="com.xt.js.gkaq.web" />
 	<context:component-scan base-package="com.xt.js.gkaq.frame" />
 	<context:component-scan base-package="com.xt.js.gkaq.dwxx" />

+ 1 - 1
gkaqv2/trunk/modules/web/src/main/webapp/WEB-INF/web.xml

@@ -87,7 +87,7 @@
 	</servlet>
 
 	<listener>
-	  <listener-class>com.xt.js.gkaq.common.util.UserSessionListener</listener-class>
+		<listener-class>com.xt.js.gkaq.web.common.util.UserSessionListener</listener-class>
 	</listener>
 
 	<!-- session过期时间 -->

+ 32 - 0
gkaqv2/trunk/modules/web/src/main/webapp/static/js/common/common.js

@@ -399,3 +399,35 @@ if (typeof constData == "undefined") {
     constData.orgType_8 = "企业";
     constData.orgType_9 = "科室";
 }
+
+(function($) {
+    // 备份jquery的ajax方法     
+    var _ajax = $.ajax;
+
+    // 重写jquery的ajax方法     
+    $.ajax = function(opt) {
+        // 备份opt中error方法     
+        var fn = {
+        }
+        if (opt.error) {
+            fn.error = opt.error;
+        }
+
+        // error方法统一处理    
+        var _opt = $.extend(opt, {
+            error : function(XMLHttpRequest, textStatus, errorThrown) {
+                if (fn.error) {
+                    fn.error(XMLHttpRequest, textStatus, errorThrown);
+                } else {
+                    // error方法增强处理     
+                    if (layer) {
+                        layer.alert("出错了,请重新登录或联系管理员!");
+                    } else {
+                        alert("出错了,请重新登录或联系管理员!");
+                    } 
+                }
+            }
+        });
+        _ajax(_opt);
+    };
+})(jQuery);

+ 2 - 8
gkaqv2/trunk/modules/web/src/main/webapp/static/js/frame/dict.js

@@ -273,9 +273,6 @@ function editInfo() {
                 $("#sortno").val(data.sortno);
                 $("#remark").val(data.remark);
                 showModelDialog("editWin", "编辑");
-            },
-            error : function(XMLHttpRequest, textStatus, errorThrown) {
-                layer.alert("error:" + errorThrown);
             }
         });
     }
@@ -306,7 +303,7 @@ function delInfo() {
                 },
                 error : function(XMLHttpRequest, textStatus, errorThrown) {
                     layer.close(index);
-                    layer.alert("error:" + errorThrown);
+                    layer.alert("出错了,请重新登录或联系管理员!");
                 }
             });
         });
@@ -354,7 +351,7 @@ function save() {
         dataType : 'json',
         data : $('#editForm').serialize(), // 表单序列化,获取数据
         success : function(data) {
-            // 成功后刷新页面
+            // 成功保存后刷新页面
             if (data && data.success == true) {
                 layer.alert("数据已成功保存!");
                 closeWin();
@@ -365,9 +362,6 @@ function save() {
             } else {
                 layer.alert("数据保存失败!");
             }
-        }, // 操作成功后的操作!data是后台传过来的值
-        error : function(XMLHttpRequest, textStatus, errorThrown) {
-            layer.alert("error:" + errorThrown);
         }
     });
 }

+ 2 - 11
gkaqv2/trunk/modules/web/src/main/webapp/static/js/frame/group.js

@@ -267,9 +267,6 @@ function editInfo() {
                 $("#remark").val(data.remark);
                 $("#menuBtnRef").val('');
                 showModelDialog("editWin", "编辑");
-            },
-            error : function(XMLHttpRequest, textStatus, errorThrown) {
-                layer.alert("error:" + errorThrown);
             }
         });
     }
@@ -300,7 +297,7 @@ function delInfo() {
                 },
                 error : function(XMLHttpRequest, textStatus, errorThrown) {
                     layer.close(index);
-                    layer.alert("error:" + errorThrown);
+                    layer.alert("出错了,请重新登录或联系管理员!");
                 }
             });
         });
@@ -361,7 +358,7 @@ function save() {
         dataType : 'json',
         data : $('#editForm').serialize(), // 表单序列化,获取数据
         success : function(data) {
-            // 成功后刷新页面
+            // 成功保存后刷新页面
             if (data && data.success == true) {
                 layer.alert("数据已成功保存!");
                 closeWin();
@@ -370,9 +367,6 @@ function save() {
             } else {
                 layer.alert("数据保存失败!");
             }
-        }, // 操作成功后的操作!data是后台传过来的值
-        error : function(XMLHttpRequest, textStatus, errorThrown) {
-            layer.alert("error:" + errorThrown);
         }
     });
 }
@@ -464,9 +458,6 @@ function editAuthInfo() {
                 $("#role").prop('readonly', 'readonly');
                 $("#menuTreeDiv").show();
                 showModelDialog("editWin", "编辑");
-            },
-            error : function(XMLHttpRequest, textStatus, errorThrown) {
-                layer.alert("error:" + errorThrown);
             }
         });
     }

+ 2 - 11
gkaqv2/trunk/modules/web/src/main/webapp/static/js/frame/menu.js

@@ -329,9 +329,6 @@ function editInfo() {
                     $("#btnIcon").val(data.icon);
                     $("#btnRemark").val(data.remark);
                     showModelDialog("editBtnWin", "编辑");
-                },
-                error : function(XMLHttpRequest, textStatus, errorThrown) {
-                    layer.alert("error:" + errorThrown);
                 }
             });
         } else { // 菜单节点
@@ -361,9 +358,6 @@ function editInfo() {
                     $("#icon").val(data.icon);
                     $("#remark").val(data.remark);
                     showModelDialog("editWin", "编辑");
-                },
-                error : function(XMLHttpRequest, textStatus, errorThrown) {
-                    layer.alert("error:" + errorThrown);
                 }
             });
         }
@@ -395,7 +389,7 @@ function delInfo() {
                 },
                 error : function(XMLHttpRequest, textStatus, errorThrown) {
                     layer.close(index);
-                    layer.alert("error:" + errorThrown);
+                    layer.alert("出错了,请重新登录或联系管理员!");
                 }
             });
         });
@@ -438,7 +432,7 @@ function save() {
         dataType : 'json',
         data : $('#editForm').serialize(), // 表单序列化,获取数据
         success : function(data) {
-            // 成功删除后刷新页面
+            // 成功保存后刷新页面
             if (data && data.success == true) {
                 layer.alert("数据已成功保存!");
                 closeWin();
@@ -449,9 +443,6 @@ function save() {
             } else {
                 layer.alert("数据保存失败!");
             }
-        }, // 操作成功后的操作!data是后台传过来的值
-        error : function(XMLHttpRequest, textStatus, errorThrown) {
-            layer.alert("error:" + errorThrown);
         }
     });
 }

+ 2 - 8
gkaqv2/trunk/modules/web/src/main/webapp/static/js/frame/org.js

@@ -325,9 +325,6 @@ function editInfo() {
                 $("#level").val(data.level);
                 changeSzdSel();
                 showModelDialog("editWin", "编辑");
-            },
-            error : function(XMLHttpRequest, textStatus, errorThrown) {
-                layer.alert("error:" + errorThrown);
             }
         });
     }
@@ -358,7 +355,7 @@ function delInfo() {
                 },
                 error : function(XMLHttpRequest, textStatus, errorThrown) {
                     layer.close(index);
-                    layer.alert("error:" + errorThrown);
+                    layer.alert("出错了,请重新登录或联系管理员!");
                 }
             });
         });
@@ -417,7 +414,7 @@ function save() {
         dataType : 'json',
         data : $('#editForm').serialize(), // 表单序列化,获取数据
         success : function(data) {
-            // 成功后刷新页面
+            // 成功保存后刷新页面
             if (data && data.success == true) {
                 layer.alert("数据已成功保存!");
                 closeWin();
@@ -428,9 +425,6 @@ function save() {
             } else {
                 layer.alert("数据保存失败!");
             }
-        }, // 操作成功后的操作!data是后台传过来的值
-        error : function(XMLHttpRequest, textStatus, errorThrown) {
-            layer.alert("error:" + errorThrown);
         }
     });
 }

+ 2 - 8
gkaqv2/trunk/modules/web/src/main/webapp/static/js/frame/param.js

@@ -118,9 +118,6 @@ function editInfo() {
                 $("#clazz").val(data.clazz);
                 $("#disp").val(data.disp);
                 showModelDialog("editWin", "编辑");
-            },
-            error : function(XMLHttpRequest, textStatus, errorThrown) {
-                layer.alert("error:" + errorThrown);
             }
         });
     }
@@ -150,7 +147,7 @@ function delInfo() {
                 },
                 error : function(XMLHttpRequest, textStatus, errorThrown) {
                     layer.close(index);
-                    layer.alert("error:" + errorThrown);
+                    layer.alert("出错了,请重新登录或联系管理员!");
                 }
             });
         });
@@ -180,7 +177,7 @@ function save() {
         dataType : 'json',
         data : $('#editForm').serialize(), // 表单序列化,获取数据
         success : function(data) {
-            // 成功后刷新页面
+            // 成功保存后刷新页面
             if (data && data.success == true) {
                 layer.alert("数据已成功保存!");
                 closeWin();
@@ -188,9 +185,6 @@ function save() {
             } else {
                 layer.alert("数据保存失败!");
             }
-        }, // 操作成功后的操作!data是后台传过来的值
-        error : function(XMLHttpRequest, textStatus, errorThrown) {
-            layer.alert("error:" + errorThrown);
         }
     });
 }

+ 2 - 11
gkaqv2/trunk/modules/web/src/main/webapp/static/js/frame/role.js

@@ -205,9 +205,6 @@ function editInfo() {
                 $("#sortno").val(data.sortno);
                 $("#menuBtnRef").val('');
                 showModelDialog("editWin", "编辑");
-            },
-            error : function(XMLHttpRequest, textStatus, errorThrown) {
-                layer.alert("error:" + errorThrown);
             }
         });
     }
@@ -237,7 +234,7 @@ function delInfo() {
                 },
                 error : function(XMLHttpRequest, textStatus, errorThrown) {
                     layer.close(index);
-                    layer.alert("error:" + errorThrown);
+                    layer.alert("出错了,请重新登录或联系管理员!");
                 }
             });
         });
@@ -292,7 +289,7 @@ function save() {
         dataType : 'json',
         data : $('#editForm').serialize(), // 表单序列化,获取数据
         success : function(data) {
-            // 成功后刷新页面
+            // 成功保存后刷新页面
             if (data && data.success == true) {
                 layer.alert("数据已成功保存!");
                 closeWin();
@@ -300,9 +297,6 @@ function save() {
             } else {
                 layer.alert("数据保存失败!");
             }
-        }, // 操作成功后的操作!data是后台传过来的值
-        error : function(XMLHttpRequest, textStatus, errorThrown) {
-            layer.alert("error:" + errorThrown);
         }
     });
 }
@@ -367,9 +361,6 @@ function editAuthInfo() {
                 $("#sortnoDiv").hide();
                 $("#menuTreeDiv").show();
                 showModelDialog("editWin", "编辑");
-            },
-            error : function(XMLHttpRequest, textStatus, errorThrown) {
-                layer.alert("error:" + errorThrown);
             }
         });
     }

+ 2 - 8
gkaqv2/trunk/modules/web/src/main/webapp/static/js/frame/xzqh.js

@@ -110,9 +110,6 @@ function editInfo() {
                 $("#name").val(data.name);
                 $("#xh").val(data.xh);
                 showModelDialog("editWin", "编辑");
-            },
-            error : function(XMLHttpRequest, textStatus, errorThrown) {
-                layer.alert("error:" + errorThrown);
             }
         });
     }
@@ -142,7 +139,7 @@ function delInfo() {
                 },
                 error : function(XMLHttpRequest, textStatus, errorThrown) {
                     layer.close(index);
-                    layer.alert("error:" + errorThrown);
+                    layer.alert("出错了,请重新登录或联系管理员!");
                 }
             });
         });
@@ -173,7 +170,7 @@ function save() {
         dataType : 'json',
         data : $('#editForm').serialize(), // 表单序列化,获取数据
         success : function(data) {
-            // 成功删除后刷新页面
+            // 成功保存后刷新页面
             if (data && data.success == true) {
                 layer.alert("数据已成功保存!");
                 closeWin();
@@ -181,9 +178,6 @@ function save() {
             } else {
                 layer.alert("数据保存失败!");
             }
-        }, // 操作成功后的操作!data是后台传过来的值
-        error : function(XMLHttpRequest, textStatus, errorThrown) {
-            layer.alert("error:" + errorThrown);
         }
     });
 }

+ 2 - 8
gkaqv2/trunk/modules/web/src/main/webapp/static/js/user/index.js

@@ -302,9 +302,6 @@ function editInfo() {
                 setChkVal('#ifJob');
 
                 showModelDialog("myModal", "编辑");
-            },
-            error : function(XMLHttpRequest, textStatus, errorThrown) {
-                layer.alert("error:" + errorThrown);
             }
         });
     }
@@ -338,7 +335,7 @@ function delInfo() {
                 },
                 error : function(XMLHttpRequest, textStatus, errorThrown) {
                     layer.close(index);
-                    layer.alert("error:" + errorThrown);
+                    layer.alert("出错了,请重新登录或联系管理员!");
                 }
             });
         });
@@ -391,7 +388,7 @@ function save() {
         dataType : 'json',
         data : $('#myForm').serialize(), // 表单序列化,获取数据
         success : function(data) {
-            // 成功后刷新页面
+            // 成功保存后刷新页面
             if (data && data.success) {
                 layer.alert("数据已成功保存!");
                 closeWin();
@@ -399,9 +396,6 @@ function save() {
             } else {
                 layer.alert("数据保存失败!");
             }
-        }, // 操作成功后的操作!data是后台传过来的值
-        error : function(XMLHttpRequest, textStatus, errorThrown) {
-            layer.alert("error:" + errorThrown);
         }
     });
 }