const client = new XMLHttpRequest();
client.open("GET", "http://www.example.org/example.txt");
client.timeout = 5000;
client.ontimeout = () => {
console.error("Timeout!!");
};
client.send();XMLHttpRequestEventTarget: timeout event / notebook
XMLHttpRequestEventTarget: timeout event
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
client.addEventListener("timeout", () => {
console.error("Timeout!!");
});// In case of a timeout we hide the progress bar
// Note that this event can be listened to on the xhr object too
function errorAction(event) {
progressBar.classList.remove("visible");
log.textContent = `Upload failed: ${event.type}`;
}
xhr.upload.addEventListener("timeout", errorAction);