Provide pages for the app. Now I want to write a common js for page request timeout. Please provide ideas or cases! !
The new version of XMLHttpRequest object has a timeout attribute to control the upper limit of ajax request time.
//通常設(shè)置為0時(shí)不生效.
//設(shè)置為字符串時(shí), 如果字符串中全部為數(shù)字, 它會(huì)自動(dòng)將字符串轉(zhuǎn)化為數(shù)字, 反之該設(shè)置不生效.
設(shè)置為對(duì)象時(shí), 如果該對(duì)象能夠轉(zhuǎn)化為數(shù)字, 那么將設(shè)置為轉(zhuǎn)化后的數(shù)字.
xhr.timeout = 0; //不生效
xhr.timeout = '123'; //生效, 值為123
xhr.timeout = '123s'; //不生效
xhr.timeout = ['123']; //生效, 值為123
xhr.timeout = {a:123}; //不生效
xhr.ontimeout = function(event){
alert('請(qǐng)求超時(shí)!');
}