From 26b391452a7a629fb28d85caac3f8eba95cc1ddd Mon Sep 17 00:00:00 2001 From: Matt Strapp Date: Mon, 14 Feb 2022 20:08:16 -0600 Subject: Make responses more clear Signed-off-by: Matt Strapp --- src/public/js/form.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/public/js') 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'); -- cgit v1.2.3