-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
36 lines (34 loc) · 1.5 KB
/
index.js
File metadata and controls
36 lines (34 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
document.addEventListener("DOMContentLoaded", function() {
var form = document.getElementById('sheetdb-form');
let successToastEl = document.getElementById('successToast');
let errorToastEl = document.getElementById('errorToast');
form.addEventListener("submit", e => {
e.preventDefault(); // Prevent the default form submission
console.log('Form submitted'); // Debug log
fetch(form.action, {
method: "POST",
body: new FormData(form),
})
.then(response => {
console.log('Response received:', response); // Debug log
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
console.log('Success:', data); // Log the success response
successToastEl.style.display = 'block'; // Show the success toast notification
setTimeout(() => {
successToastEl.remove(); // Remove from DOM after 3 seconds
}, 3000); // 3000 milliseconds = 3 seconds
})
.catch(error => {
console.error('There was a problem with the fetch operation:', error);
errorToastEl.style.display = 'block'; // Show the error toast notification
setTimeout(() => {
errorToastEl.remove(); // Remove from DOM after 3 seconds
}, 3000); // 3000 milliseconds = 3 seconds
});
});
});