Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Set timeouts to XMLHttpRequests in javascript

let xhr = new XMLHttpRequest (); 
xhr.onreadystatechange = function () {  
    if (this.readyState == 4) {  
        clearTimeout(timeout);  
        // do something with response data 
    }  
}  
let timeout = setTimeout( function () {  
    xhr.abort(); // call error callback  
}, 60*1000 /* timeout after a minute */ ); 
xhr.open('GET', url, true);  

xhr.send();
Source by developer.mozilla.org #
 
PREVIOUS NEXT
Tagged: #Set #timeouts #XMLHttpRequests #javascript
ADD COMMENT
Topic
Name
9+6 =