aboutsummaryrefslogtreecommitdiff
path: root/src/js/arching-kaos-fetch.js
diff options
context:
space:
mode:
authorkaotisk <kaotisk@arching-kaos.org>2023-09-05 02:22:53 +0300
committerkaotisk <kaotisk@arching-kaos.org>2023-09-05 02:22:53 +0300
commit6433eaccbfcfe1472b94e3c8408ab125779f908a (patch)
tree74d0838c7f6750d3411392565e8ceb77b5851d5c /src/js/arching-kaos-fetch.js
parent79583dc180ef2c1561a887767204ad7c737cc0af (diff)
downloadarching-kaos-web-ui-6433eaccbfcfe1472b94e3c8408ab125779f908a.tar.gz
arching-kaos-web-ui-6433eaccbfcfe1472b94e3c8408ab125779f908a.tar.bz2
arching-kaos-web-ui-6433eaccbfcfe1472b94e3c8408ab125779f908a.zip
Moving from Fetch to XMLHttpRequest
Diffstat (limited to 'src/js/arching-kaos-fetch.js')
-rw-r--r--src/js/arching-kaos-fetch.js49
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 ){