Add event handler before executing open

Signed-off-by: RMidhunSuresh <hi@midhun.dev>
This commit is contained in:
RMidhunSuresh 2021-11-04 00:02:50 +05:30
parent b011c3df03
commit 96a2dd7c72

View file

@ -37,6 +37,11 @@ class RequestResult {
function createXhr(url, {method, headers, timeout, format, uploadProgress}) {
const xhr = new XMLHttpRequest();
if (uploadProgress) {
xhr.upload.addEventListener("progress", evt => uploadProgress(evt.loaded));
}
xhr.open(method, url);
if (format === "buffer") {
@ -56,10 +61,6 @@ function createXhr(url, {method, headers, timeout, format, uploadProgress}) {
xhr.timeout = timeout;
}
if (uploadProgress) {
xhr.upload.addEventListener("progress", evt => uploadProgress(evt.loaded));
}
return xhr;
}