Is onload
equivalent to onreadystatechange
with readyState
4, status
200?
But if they are equivalent, then why does this MDN article nest the two as such:
var xhr = new XMLHttpRequest();
xhr.open("GET", "/bar/foo.txt", true);
xhr.onload = function (e) {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
console.log(xhr.responseText);
} else {
console.error(xhr.statusText);
}
}
};
xhr.onerror = function (e) {
console.error(xhr.statusText);
};
xhr.send(null);
[EDIT] Not duplicate of:
Is onload equal to readyState==4 in XMLHttpRequest?
The second answer in the above post explains that it is not exactly the same as readyState === 4
. However, if you include status === 200
you have addressed the difference he/she talks about. My OP shows status
nested inside readyState
.