aboutsummaryrefslogtreecommitdiffstats
path: root/src/public/js/form.js
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/public/js/form.js21
1 files changed, 11 insertions, 10 deletions
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