diff options
Diffstat (limited to 'src/public/js')
-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'); |