From b1b5317ec9a1d3f288272fed2959bd694e9ffdbf Mon Sep 17 00:00:00 2001 From: NI Date: Thu, 13 Aug 2020 22:15:10 +0800 Subject: [PATCH] xhr.js: Use `AddEventListener` instead of directly overwrite the callback --- ui/xhr.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ui/xhr.js b/ui/xhr.js index 188bc5c..b8645a1 100644 --- a/ui/xhr.js +++ b/ui/xhr.js @@ -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);