This might be a very obvious question but please explain what is the difference between xhr
and xhr.upload
?
My use case is that I am uploading a file to a server but suppose the server goes down. In this case should I handle xhr.onerror
or xhr.upload.onerror
Basically, as mentioned in the question, when to use xhr and when to use xhr.upload
where xhr = new XMLHttpRequest();
Another newbie question on the same, is it related to how GET vs POST/PUT are handled?
xhr.onerror
fires when there is a failure on the network level. If the error only exists on the application level, e.g., an HTTP error code is sent, then onload still fires.
You need to test the returned status code explicitly in your onreadystatuschange handler.
where as xhr.upload.onerror
fires something happend when you are trying to upload, this is basically application level function just like xhr.upload.Onprogress
.
This upload always depends upon the ajax post method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With