search

Home  >  Q&A  >  body text

javascript - How to implement universal page request timeout processing in js?

Provide pages for the app. Now I want to write a common js for page request timeout. Please provide ideas or cases! !

我想大声告诉你我想大声告诉你2829 days ago645

reply all(2)I'll reply

  • PHP中文网

    PHP中文网2017-05-19 10:31:39

    The new version of XMLHttpRequest object has a timeout attribute to control the upper limit of ajax request time.

        //通常设置为0时不生效.
        //设置为字符串时, 如果字符串中全部为数字, 它会自动将字符串转化为数字, 反之该设置不生效.
        设置为对象时, 如果该对象能够转化为数字, 那么将设置为转化后的数字.
        
        xhr.timeout = 0; //不生效
        xhr.timeout = '123'; //生效, 值为123
        xhr.timeout = '123s'; //不生效
        xhr.timeout = ['123']; //生效, 值为123
        xhr.timeout = {a:123}; //不生效
        
        
        xhr.ontimeout = function(event){
          alert('请求超时!');
        }
        

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-05-19 10:31:39

    jquery angularjs has timeout

    reply
    0
  • Cancelreply