-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
43 lines (39 loc) · 1.45 KB
/
script.js
File metadata and controls
43 lines (39 loc) · 1.45 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
37
38
39
40
41
42
43
document.getElementById('wishesForm').addEventListener('submit', function(event) {
event.preventDefault(); // Prevent form submission
// Get form data
var message = document.getElementById('message').value;
var contact = document.getElementById('contact').value;
var date = document.getElementById('date').value;
var time = document.getElementById('time').value;
// Construct datetime string
var datetimeString = date + ' ' + time + ':00';
// Create request body
var requestBody = {
message: message,
contact: contact,
datetime: datetimeString
};
// Send POST request to backend API
fetch('http://localhost:5000/send_wishes', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(requestBody)
})
.then(response => {
if (response.ok) {
console.log('Wishes sent successfully!');
// Clear form fields (optional)
document.getElementById('message').value = '';
document.getElementById('contact').value = '';
document.getElementById('date').value = '';
document.getElementById('time').value = '';
} else {
console.error('Failed to send wishes:', response.status);
}
})
.catch(error => {
console.error('Error sending wishes:', error);
});
});