admin管理员组文章数量:1321252
It seems to be possible to set a timeout value when doing an Ajax request in plain javascript. see How to detect timeout on an AJAX (XmlHttpRequest) call in the browser?
It is also possible when using jQuery's ajax implementation, & other similar frameworks I assume. see Set timeout for ajax (jQuery)
Browsers seem to have rather vague specification regarding their default timeout. see Browser Timeouts
Hence one might "hey, I'm going to set a timeout to my ajax request so all the users will have the same timeout".
But then, the next question follow: would it actually override the browser's timeout in all cases?
When I say "all" cases, I mean for instance, if the browser timeout value is smaller than your ajax request timeout value.
I suspect it does not.
And I also suspect it is best practice to always have a timeout error handler to make sure that whatever happens you can display a relevant message that will save hours of work to your support team, & money to your pany. see Determine if $.ajax error is a timeout
Thanks in advance
It seems to be possible to set a timeout value when doing an Ajax request in plain javascript. see How to detect timeout on an AJAX (XmlHttpRequest) call in the browser?
It is also possible when using jQuery's ajax implementation, & other similar frameworks I assume. see Set timeout for ajax (jQuery)
Browsers seem to have rather vague specification regarding their default timeout. see Browser Timeouts
Hence one might "hey, I'm going to set a timeout to my ajax request so all the users will have the same timeout".
But then, the next question follow: would it actually override the browser's timeout in all cases?
When I say "all" cases, I mean for instance, if the browser timeout value is smaller than your ajax request timeout value.
I suspect it does not.
And I also suspect it is best practice to always have a timeout error handler to make sure that whatever happens you can display a relevant message that will save hours of work to your support team, & money to your pany. see Determine if $.ajax error is a timeout
Thanks in advance
Share Improve this question edited May 23, 2017 at 12:18 CommunityBot 11 silver badge asked Jul 2, 2014 at 8:19 AdrianoAdriano 20k19 gold badges105 silver badges140 bronze badges 3- 2 Based on this morgb.blogspot.de/2014/05/… I would guess "not at least on firefox. This answer claims there is no way to override. stackoverflow./questions/1192375/… – Marcus Commented Jul 2, 2014 at 16:12
- Do you know the "plete", "success" and "error" settings of AJAX yet? I mean, why you gonna need a timeOut function when you have the "plete" setting that response when the request is end? – Fernando Torres Commented Mar 21, 2017 at 2:52
- @FernandoUrban yes I do. The question is about setting a same timeout value regardless of the browser (browser's timeout). Not about acting according to timeout (whether you do it in "plete" or "error"). – Adriano Commented Mar 21, 2017 at 21:02
1 Answer
Reset to default 6It is an interesting question, I made some experiments in Chrome 59.0 and Firefox 54.0 using a 10min delay service as the backend.
After some test setting the timeout on the client to 10 minutes I had an error response with text status "error" after 300 seconds (5 minutes) in both browsers, so at least for these two browsers it is not possible to override the internal timeout value. I am assuming the same behavior for the remaining browsers in the market.
My test script: (similar results for vanilla JavaScript)
var st = new Date();
$.ajax({
url: "https//mysitewith10minresponse./foobar",
type: "GET",
dataType: "json",
timeout: 600000,
success: function(response) { console.log(response); },
error: function(jqXHR, textStatus, errorThrown) {
st = (new Date() - st)/1000;
alert("Text Status " + textStatus + ", diff: " + st + " seconds");
}
});
本文标签: javascriptAjax does setting timeout always override the browser39s timeoutStack Overflow
版权声明:本文标题:javascript - Ajax: does setting timeout always override the browser's timeout? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742094422a2420460.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论