-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapifetch.js
72 lines (65 loc) · 2.71 KB
/
apifetch.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
function loadActivities(type) {
const apiUrl = `http://54.169.66.11:3005/api/activityRoute/one`;
fetch(apiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ type: type })
})
.then(response => response.json())
.then(data => {
const activitiesContainer = document.getElementById('activities-container');
if (!activitiesContainer) {
console.error('activities-container not found in the DOM');
return;
}
activitiesContainer.innerHTML = '';
data.data.forEach(activity => {
const activityHTML = `
<div class="capsule-activity py-2" data-type="${activity.type}">
<img src="${activity.images[0].url}" alt="Activity Image" height="100%">
<div class="content ms-3 px-4">
<div class="d-flex justify-content-between align-items-center">
<h3 class="display-6 ">${activity.name}</h3>
<p class="px-4 py-2 bg-black text-white rounded px-4">${activity.type.charAt(0).toUpperCase() + activity.type.slice(1)}</p>
</div>
<p>${activity.description}</p>
</div>
</div>
`;
activitiesContainer.innerHTML += activityHTML;
});
})
.catch(error => {
console.error('Error fetching activities:', error);
});
}
window.addEventListener('DOMContentLoaded', function () {
loadActivities('indoor');
});
window.addEventListener('DOMContentLoaded', function () {
const contactForm = document.getElementById('contact-form');
if (contactForm) {
contactForm.addEventListener('submit', function (event) {
event.preventDefault();
const formData = new FormData(contactForm);
fetch('http://54.169.66.11:3005/api/user/contact', {
method: 'POST',
body: formData,
})
.then(response => response.json())
.then(data => {
console.log('Success:', data);
alert('Message sent successfully!');
this.reset();
})
.catch(error => {
console.error('Error:', error);
alert('There was an error sending your message.');
});
});
} else {
console.error('Form with ID contact-form not found');
}
});