diff options
author | kaotisk <kaotisk@arching-kaos.org> | 2023-09-05 02:22:53 +0300 |
---|---|---|
committer | kaotisk <kaotisk@arching-kaos.org> | 2023-09-05 02:22:53 +0300 |
commit | 6433eaccbfcfe1472b94e3c8408ab125779f908a (patch) | |
tree | 74d0838c7f6750d3411392565e8ceb77b5851d5c | |
parent | 79583dc180ef2c1561a887767204ad7c737cc0af (diff) | |
download | arching-kaos-web-ui-6433eaccbfcfe1472b94e3c8408ab125779f908a.tar.gz arching-kaos-web-ui-6433eaccbfcfe1472b94e3c8408ab125779f908a.tar.bz2 arching-kaos-web-ui-6433eaccbfcfe1472b94e3c8408ab125779f908a.zip |
Moving from Fetch to XMLHttpRequest
-rw-r--r-- | src/js/arching-kaos-fetch.js | 49 |
1 files changed, 37 insertions, 12 deletions
diff --git a/src/js/arching-kaos-fetch.js b/src/js/arching-kaos-fetch.js index 91e2419..bc982f9 100644 --- a/src/js/arching-kaos-fetch.js +++ b/src/js/arching-kaos-fetch.js @@ -1,18 +1,43 @@ function archingKaosFetchJSON( url, callback ){ - fetch(url, { - method:'GET', - headers:{ - Accept: 'application/json' - } - }).then(response=>{ - if(response.ok){ - response.json().then(json=>{ - callback(json); - }) +// fetch(url, { +// method:'GET', +// headers:{ +// Accept: 'application/json' +// } +// }).then(response=>{ +// if(response.ok){ +// response.json().then(json=>{ +// callback(json); +// }) +// } else { +// if (DEBUG) console.log(e); +// } +// }).catch( e=>{ +// if (DEBUG) console.log(e); +// }) + const request = new XMLHttpRequest(); + request.addEventListener("load", ()=>{ + console.log(request.response); + var json = JSON.parse(request.response); + callback(json); + }); + request.addEventListener("error", ()=>{ + console.log("An error occured."); + }); + request.addEventListener("progress", (event)=>{ + console.log(request.response); + if (event.lengthComputable && progressPlaceholder){ + progressPlaceholder = (event.loaded / event.total) * 100; } else { - if (DEBUG) console.log(e); + progressPlaceholder = 0; } - }) + }); + request.addEventListener("abort", ()=>{ + console.log("Request aborted."); + }); + request.open("GET", url); + request.send(); + } async function archingKaosFetchText( url, callback ){ |