diff options
author | Matt Strapp <matt@mattstrapp.net> | 2022-02-14 20:08:16 -0600 |
---|---|---|
committer | Matt Strapp <matt@mattstrapp.net> | 2022-02-14 20:25:15 -0600 |
commit | 26b391452a7a629fb28d85caac3f8eba95cc1ddd (patch) | |
tree | a3220d10cdee3aa125c02648ab8e38d64380ae5c /src/public/js/form.js | |
parent | Update some dependencies (diff) | |
download | ee4511w-web-26b391452a7a629fb28d85caac3f8eba95cc1ddd.tar ee4511w-web-26b391452a7a629fb28d85caac3f8eba95cc1ddd.tar.gz ee4511w-web-26b391452a7a629fb28d85caac3f8eba95cc1ddd.tar.bz2 ee4511w-web-26b391452a7a629fb28d85caac3f8eba95cc1ddd.tar.lz ee4511w-web-26b391452a7a629fb28d85caac3f8eba95cc1ddd.tar.xz ee4511w-web-26b391452a7a629fb28d85caac3f8eba95cc1ddd.tar.zst ee4511w-web-26b391452a7a629fb28d85caac3f8eba95cc1ddd.zip |
Make responses more clear
Signed-off-by: Matt Strapp <matt@mattstrapp.net>
Diffstat (limited to '')
-rw-r--r-- | src/public/js/form.js | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/public/js/form.js b/src/public/js/form.js index f58a27f..581d5a3 100644 --- a/src/public/js/form.js +++ b/src/public/js/form.js @@ -4,10 +4,12 @@ window.onload = function () { }; // File submit AJAX request +// After successful upload, actuate the file by calling actuate() on the successfully uploaded file document.getElementById('upload').onsubmit = function () { - // Reset error message + // Reset error message and success message document.getElementById('upload-err').innerText = ''; document.getElementById('actuate-err').innerText = ''; + document.getElementById('upload-response').innerText = ''; // Make AJAX request let xhr = new XMLHttpRequest(); xhr.open('POST', '/api/v1/upload'); @@ -16,7 +18,9 @@ document.getElementById('upload').onsubmit = function () { xhr.onreadystatechange = function () { if (xhr.readyState === 4) { let response = JSON.parse(xhr.responseText); - if (xhr.status === 200) { + if (xhr.status === 201) { + // Display upload success message to the user + document.getElementById('upload-response').innerText = response.msg; actuate(response); } else { // Display upload error message to the user @@ -27,9 +31,14 @@ document.getElementById('upload').onsubmit = function () { } } }; + document.getElementById('upload').reset(); return false; }; +// Actuate button AJAX request +// Should always be called after upload +// Implies that upload has been successful since it relies on the upload response +// function actuate(file) { let xhr = new XMLHttpRequest(); xhr.open('POST', '/api/v1/actuate'); |