如何处理Ajax调用上的超时错误 [英] How to handle timeout error on ajax call
本文介绍了如何处理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调用上的超时错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文