what is the maximum timeout can be set in jquery ajax?

穿精又带淫゛_ 提交于 2019-12-05 09:15:59

My previous answer was wrong (timeout just seemed to be to short and I couldn't believe it myself) so I have done a test yesterday, created 1GB zip then throttled my connection with fiddler and wrote this aspx page.

public partial class Ajaxtest : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Clear();
            Response.BufferOutput = false; 
            Response.WriteFile("c://OnTheMoveOffline.zip");
        }
    }

then I ran this script (interestingly fiddler blew up with OutOfMemory exception within 10 seconds however response was held).

var f = function(){ 
var compareDate = new Date();
$.ajax({
 url : 'http://localhost:22037/FeatureDev/Ajaxtest.aspx',
success: function(data){ console.log(Math.abs(new Date() - compareDate));},
error : function(e){ console.log(Math.abs(new Date() - compareDate));},
timeout : 10000000
}).done(function() {
    console.log(Math.abs(new Date() - compareDate));
  })
  .fail(function() {
    console.log(Math.abs(new Date() - compareDate));
  })
  .always(function() {
    console.log(Math.abs(new Date() - compareDate));
  });}

It came back with

9393076 
9393081 
9393081 

9393076/1000 ~ 9393(s) = 02:36:33

Which equals to ~156 minutes.

I will repeat this test this weekend to see if it will timeout after same amount of time, but so far it seems it is more than 7200000 (2*60*60*1000).

Xawery Wiśniowiecki

Default global value of timeout is 0 that means it is infinite.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!