-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
34 lines (31 loc) · 898 Bytes
/
script.js
File metadata and controls
34 lines (31 loc) · 898 Bytes
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
// script.js
document.getElementById("contactForm").addEventListener("submit", async (e) => {
e.preventDefault();
document.body.classList.add("sent");
// Get form data
const name = document.getElementById("name").value;
const email = document.getElementById("email").value;
const phone = document.getElementById("phone").value;
// Create contact object
const contact = {
name,
email,
phone,
};
try {
const response = await fetch("http://localhost:8080/api/contacts/", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(contact),
});
if (response.ok) {
console.log("Contact created successfully!");
} else {
console.error("Error creating contact:", response.statusText);
}
} catch (error) {
console.error("Error creating contact:", error.message);
}
});