Ajax: does setting timeout always override the browser's timeout?

前端 未结 1 1316
忘掉有多难
忘掉有多难 2021-01-17 14:54

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?

相关标签:
1条回答
  • 2021-01-17 15:10

    It 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.com/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");          
          }
      });
    
    0 讨论(0)
自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题