xhr.js: Use AddEventListener instead of directly overwrite the callback

This commit is contained in:
NI
2020-08-13 22:15:10 +08:00
parent a848062795
commit b1b5317ec9

View File

@@ -19,21 +19,21 @@ export function get(url, headers) {
return new Promise((res, rej) => {
let authReq = new XMLHttpRequest();
authReq.onreadystatechange = () => {
authReq.addEventListener("readystatechange", () => {
if (authReq.readyState !== authReq.DONE) {
return;
}
res(authReq);
};
});
authReq.onerror = e => {
authReq.addEventListener("error", (e) => {
rej(e);
};
});
authReq.ontimeout = e => {
authReq.addEventListener("timeout", (e) => {
rej(e);
};
});
authReq.open("GET", url, true);