From dc208478fd18a4e28c0083641bf405170859fc58 Mon Sep 17 00:00:00 2001 From: "caleb.mabry.15@cnu.edu" Date: Thu, 10 Mar 2022 23:21:38 -0500 Subject: Magnum Opus pt1 --- webAO/utils/fileExists.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 webAO/utils/fileExists.js (limited to 'webAO/utils/fileExists.js') diff --git a/webAO/utils/fileExists.js b/webAO/utils/fileExists.js new file mode 100644 index 0000000..261acda --- /dev/null +++ b/webAO/utils/fileExists.js @@ -0,0 +1,17 @@ +const fileExists = async (url) => { + const xhr = new XMLHttpRequest(); + xhr.open('GET', url, true); + xhr.onload = function (e) { + if (xhr.readyState === 4) { + if (xhr.status === 200) { + return true; + } + return false; + } + }; + xhr.onerror = function (e) { + return false; + }; + xhr.send(null); +}; +export default fileExists; -- cgit From 70f33fd0c1c931ca3859a7dce1a1272fd2863fbc Mon Sep 17 00:00:00 2001 From: "caleb.mabry.15@cnu.edu" Date: Fri, 11 Mar 2022 01:17:16 -0500 Subject: Resolving issue 99 --- webAO/utils/fileExists.js | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) (limited to 'webAO/utils/fileExists.js') diff --git a/webAO/utils/fileExists.js b/webAO/utils/fileExists.js index 261acda..6d32a1e 100644 --- a/webAO/utils/fileExists.js +++ b/webAO/utils/fileExists.js @@ -1,17 +1,8 @@ const fileExists = async (url) => { const xhr = new XMLHttpRequest(); - xhr.open('GET', url, true); - xhr.onload = function (e) { - if (xhr.readyState === 4) { - if (xhr.status === 200) { - return true; - } - return false; - } - }; - xhr.onerror = function (e) { - return false; - }; - xhr.send(null); + xhr.open('HEAD', url, false); + xhr.send(); + + return xhr.status === 200; }; export default fileExists; -- cgit