From e9cc00f8947d3aea0f802a8b8d7f2e406c3fcb1f Mon Sep 17 00:00:00 2001 From: Matt Strapp Date: Fri, 11 Feb 2022 11:30:40 -0600 Subject: Finish upload API endpoint Signed-off-by: Matt Strapp --- src/public/js/form.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'src/public') diff --git a/src/public/js/form.js b/src/public/js/form.js index cfa80fd..7085422 100644 --- a/src/public/js/form.js +++ b/src/public/js/form.js @@ -1,17 +1,18 @@ +// File submit AJAX request document.getElementById('upload').onsubmit = function () { - var data = new FormData(document.getElementById('upload')); - var xhr = new XMLHttpRequest(); - xhr.open('POST', '/api/upload'); - xhr.send(data); + let xhr = new XMLHttpRequest(); + xhr.open('POST', '/api/v1/upload'); + let formData = new FormData(this); + xhr.send(formData); xhr.onreadystatechange = function () { - if (xhr.readyState == 4 && xhr.status == 200) { - var response = JSON.parse(xhr.responseText); - if (response.success) { - document.getElementById('success').style.display = 'block'; + if (xhr.readyState === 4) { + let response = JSON.parse(xhr.responseText); + if (xhr.status === 200) { + console.log(response); } else { - document.getElementById('error').style.display = 'block'; + console.log(response.error); } } }; return false; -}; +}; \ No newline at end of file -- cgit v1.2.3