javascript - How to implement universal page request timeout processing in js?
我想大声告诉你
我想大声告诉你 2017-05-19 10:29:39
0
2
603

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

我想大声告诉你
我想大声告诉你

reply all(2)
洪涛

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('请求超时!');
    }
    
我想大声告诉你

jquery angularjs has timeout

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template