-
Notifications
You must be signed in to change notification settings - Fork 0
/
home.js
37 lines (35 loc) · 1019 Bytes
/
home.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
document.getElementById('journal-form').addEventListener('submit', function (event) {
event.preventDefault();
const content = document.getElementById('entry').value;
const mood = document.getElementById('mood').value;
if (content && mood) {
const entry = {
content: content,
mood: mood
};
fetch('http://127.0.0.1:5000/entry', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(entry),
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
alert(data.message);
document.getElementById('entry').value = '';
document.getElementById('mood').value = 3;
})
.catch(error => {
console.error('Error:', error);
alert('Error saving entry: ' + error.message);
});
} else {
alert('Please fill out all the required fields.');
}
});