-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.js
79 lines (67 loc) · 2.35 KB
/
config.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Contact Form Submission
const contactForm = document.getElementById('contactForm');
const contactResponseMessage = document.getElementById('response-message');
contactForm.addEventListener('submit', function(event) {
event.preventDefault();
const name = document.getElementById('name').value;
const email = document.getElementById('email').value;
const description = document.getElementById('description').value;
const formData = { name, email, description };
// Send form data to server via Fetch API
fetch('http://localhost:5500/contact', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(formData)
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
if (contactResponseMessage) {
contactResponseMessage.innerHTML = `<p>${data.message}</p>`;
}
})
.catch(error => {
if (contactResponseMessage) {
contactResponseMessage.innerHTML = `<p>Error: ${error.message}</p>`;
}
});
});
// Newsletter Subscription
const newsletterForm = document.querySelector('.newsletter form');
const newsletterResponseMessage = document.createElement('div');
newsletterForm.appendChild(newsletterResponseMessage);
newsletterForm.addEventListener('submit', function(event) {
event.preventDefault();
const email = document.getElementById('newsletteremail').value;
const formData = { email };
// Send form data to server via Fetch API
fetch('http://localhost:5500/newsletter', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(formData)
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
if (newsletterResponseMessage) {
newsletterResponseMessage.innerHTML = `<p>${data.message}</p>`;
}
})
.catch(error => {
if (newsletterResponseMessage) {
newsletterResponseMessage.innerHTML = `<p>Error: ${error.message}</p>`;
}
});
});