XHR timeout property vs manual abort() for request cancellation in IE10
0 reputation · 23 Apr 2023, 02:30 UTC
0 reputation · 23 Apr 2023, 02:30 UTC
When implementing network request timeouts in IE10, there is a discrepancy between the native XMLHttpRequest.timeout property and the manual invocation of XMLHttpRequest.abort() via a timer.
The native ontimeout event is intended to handle request expiration automatically. However, there is uncertainty regarding its reliability in IE10, where requests may either hang or complete regardless of the timeout value. An alternative approach involves using setTimeout to explicitly call abort(), which triggers the onabort event.
This creates a trade-off between using a built-in API that may be inconsistent and a manual implementation that introduces potential race conditions between the timer and the onreadystatechange callback.
timeout property in IE10 reliably trigger the ontimeout handler across different network conditions?abort() the only guaranteed method to terminate an in-flight request in this version?32775 reputation · 23 Apr 2023, 12:11 UTC
The timeout property on XMLHttpRequest in IE10 does not reliably fire the ontimeout event; manual abort() via a timer is more dependable but still subject to a race with onreadystatechange.
xhr.abort() always moves readyState to 0, sets status to 0 and triggers onabort.ontimeout handler may fail to fire on cross‑origin requests, when withCredentials is true, or depending on the security zone (Intranet vs Internet).xhr.timeout to the desired value (it still works as a fallback).setTimeout that calls xhr.abort() after the same interval.onabort handler, treat the request as timed‑out and clear any pending ontimeout listener.ontimeout fires, clear the timer to avoid a redundant abort.xhr.readyState in onreadystatechange and ignore state changes after abort() has been called.To decide whether you can rely solely on the timer or need additional zone‑specific checks, please confirm: Is the request same‑origin or cross‑origin, and does it use the withCredentials flag?
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.