-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
35 lines (24 loc) · 811 Bytes
/
script.js
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
const myForm = document.getElementById("myForm");
myForm.addEventListener("submit", handleSubmit);
function handleSubmit(event) {
event.preventDefault();
const formData = new FormData(myForm);
fetch("http://localhost:8000/api/post", {
method: "POST",
body: formData,
})
.then(response => response.json())
.then(data => {
// Handle successful response
alert("Thank you for joining us, we will soon contact you!!")
// window.location = "/";
})
.catch(error => {
// Handle error response
if (error instanceof TypeError) {
alert("Network error. Please try again later.");
} else if (error instanceof Error) {
alert(error.message);
}
});
}