I was re-watching a video from WWDC12 on advanced effects with HTML5 and noticed that for the demo they used req.addEventListener("load",callback,true) rather than the usual onreadystatechange.
What are the differences between the load event and state=4 status=200 situation?
Is it the same load event being fired or two different ones?
The
loadevent only indicates that the request was a network success, not necessarily an HTTP success. An Ajax request with always either fire aloadevent or anerrorevent, indicating the success or failure of the network transaction (as part of the Progress Events specification):The
errorevent fires when the network fetch fails due to the server being down or on an inaccessible domain (i.e., the request is blocked by the same-origin policy).Otherwise,
loadfires, regardless of the HTTP code returned.The
loadorerrorevent always fires last, after the lastreadstatechangeevent has fired, so you can be sure that theloadorerrorcallback is running withxhr.readyState == 4andxhr.statusset to the correct HTTP response code.