如何处理Ajax调用上的超时错误

编程入门 行业动态 更新时间:2024-10-16 00:23:51
本文介绍了如何处理Ajax调用上的超时错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想处理ajax调用中的超时错误,因为我已将会话超时设置为1分钟,如..

I want to handle timeout error on ajax call where i have set session timeout to 1 minute like..

<authentication mode="Forms"> <forms loginUrl="~/User/Login" timeout="1" /> </authentication>

我对每个ajax请求的调用就像..

and my call for every ajax request is like..

$.ajax({ url: ''../Document/getData?did='' + docid2, beforeSend: function () { $("#DialogData").empty().html(''<p class="Loadimg"></p>''); }, success: function (result) { $("#DialogData").load(''../Document/getData?did='' + docid2); }, error: function (req, status, xhr) { alert(xhr); //for Timeout Error if (status == "timeout") { $("#DialogData").empty().html(''<p>Plese Try Again</p><''); } if (status == "error") { //for Page Not Found Invalid URL if (xhr == "Not Found") { } //for server error which is from controller if (xhr == "Internal Server Error") { } } //if error } //error }); //Ajax

但是在超时时,我收到内部服务器错误...我想以不同于其他错误的方式处理超时错误,所以我该怎么办..

but on timeout i get internal server error...i want to handle timeout error differently than other error so what should i do..

推荐答案

.ajax({ 网址:"../Document/getData?did =" + docid2, beforeSend:function(){ .ajax({ url: ''../Document/getData?did='' + docid2, beforeSend: function () {

(#DialogData").empty().html(''< p class ="Loadimg"></p>'') ; }, 成功:函数(结果){ ("#DialogData").empty().html(''<p class="Loadimg"></p>''); }, success: function (result) {

(#DialogData").load(''../Document/getData?did =''+ docid2);; }, 错误:功能(要求,状态,xhr){ 警报(xhr); //用于超时错误 if(状态==超时"){ ("#DialogData").load(''../Document/getData?did='' + docid2); }, error: function (req, status, xhr) { alert(xhr); //for Timeout Error if (status == "timeout") {

更多推荐

如何处理Ajax调用上的超时错误

本文发布于:2023-11-25 23:30:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1631784.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何处理   错误   Ajax

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!