前台页面 ajax 异常统一处理。
2017-09-25 00:00
471 查看
/** * 公共服务类 */ function commService() { }; commService.prototype.ajax = function(data,url,success,error){ commService.prototype.ajax = function(data,url,success,error){ $.ajax({ url:url, dataType:"json", contentType : "application/x-www-form-urlencoded;charset=utf-8", type:"post", async : false, data:{"data":JSON.stringify(data),"key":"xxxx","devicetype":"WEB"}, success:function(data, status){ console.log(status); if(typeof success =='function'){ success(data,status); } }, error:function(XMLHttpRequest, textStatus, errorThrown){ // console.log(XMLHttpRequest.responseText); // console.log(XMLHttpRequest.status);//状态码 404 500 // console.log(XMLHttpRequest.readyState);//当前状态,0-未初始化,1-正在载入,2-已经载入,3-数据进行交互,4-完成。 // console.log(textStatus);//"timeout"(超时), "error"(错误), "abort"(中止), "parsererror"(解析错误) if(typeof error =='function'){ error(XMLHttpRequest.responseText,textStatus,XMLHttpRequest,errorThrown); }else if(XMLHttpRequest.status=="500"){ alert("服务器异常 ,请联系开发人员!"); console.error(XMLHttpRequest.responseText); } }); }; var commService = new commService(); /** * 测试调用 例子 */ /** var data = {"userId":"1"}; commService.ajax(data,"../../test.do",function(data){ }); **/
( 本代码引入jquery 1.9.1)
相关文章推荐
- 扩展jQuery的方法统一处理AJAX调用过程中产生的异常错误信息
- Web应用中设置了异常统一处理页面,捕捉指定异常时的处理问题
- JS处理前台页面的所有异常
- nodejs读取mongodb返回数据到前台页面[object object]异常处理
- 关于jQuery load()方法加载页面后台发生异常而前台页面加载失败且没有任何展示信息的问题处理
- JS处理前台页面的所有异常
- Struts2、Spring MVC4 框架下的ajax统一异常处理
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法(2):处理异步调用中的异常
- JS处理前台页面的所有异常
- 想抛就抛:Application_Error中统一处理ajax请求执行中抛出的异常
- java异常处理,ajax调用后台异常,页面跳转
- ajax和普通请求使用spring mvc在controller中的异常统一处理
- 封装ajax方法(统一处理登录超时异常)
- springmvc统一处理ajax异常
- spring mvc 异常(runtime异常、ajax异常)统一处理与范例
- 利用委托统一处理web页面的异常信息
- spring-boot统一处理返回给前台的数据格式(避免返回异常堆栈信息,干扰用户体验)
- spring boot统一异常处理
- SpringBoot(七)_统一异常处理
- 页面报出uncaught exception: out of memory异常,如何处理