I am facing a bit of confusion when trying to understand the functionality of XMLHttpRequest
's handlers. After reading the specification regarding the onerror
handler, it mentions:
error
[Dispatched ... ] When the request has failed.
load
[Dispatched ... ] When the request has successfully completed.
The issue lies in determining what exactly constitutes as "the request has failed". This could mean
- the request was unable to be sent at all (e.g., Connection refused and similar errors), or
- the above scenario plus receiving an error code from the server (e.g., 404)
Furthermore, I am curious to know if this implies that onerror
and onload
should never trigger simultaneously.
According to this resource, the execution of the onerror
handler is dependent on the status
code, while onload
depends on the readyState
. Although this suggests they are not mutually exclusive, I am unsure if this information holds authoritative weight.
I am seeking clarification because when using the latest Opera snapshot, I noticed that onload
is being triggered even when encountering a 404 status code. While checking the status
is a reliable method, I am uncertain whether this aligns with the specifications or if it's simply a workaround for an issue in Opera.