The .onerror
will only be invoked if there is an error at the network level, otherwise it will always enter .onload
and ignore onerror
.
Example:
Suppose I am in the http://meusite.com
site and I have a index.html
file in the root directory.
If I try to call xhr.open("GET","index.html",true);
:
- You will enter%% with without error , with
onload
, because
found the file normally.
If I try to call xhr.status == 200
:
- It will enter the% w / w with error "(actually not an error, but only a return that the file was not found), with
xhr.open("GET","indexxxxx.html",true);
, because
did not find the file.
If I try to call onload
:
- Will enter
xhr.status == 404
, as it is not allowed to call domain
different from the current one and the request was not even sent.
The
xhr.open("GET","http://google.com",true);
are phases of communication with the server (from 0 to 4), while
onerror
is interpreted by the browser (200, 404 etc ...)