Answers for "Set timeouts to XMLHttpRequests in javascript"

0

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();
Posted by: Guest on December-08-2020

Code answers related to "Set timeouts to XMLHttpRequests in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language