-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathappendUsers.js
31 lines (27 loc) · 985 Bytes
/
appendUsers.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
// Append new users by making a POST request to the Node.js server
const appendUsers = () => {
console.log('Appending new users...');
fetch('http://127.0.0.1:8080/append-users', {
method: 'POST',
})
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.text();
})
.then(data => {
alert(data); // Notify user of success
console.log('Users appended:', data);
// Optionally re-fetch data to display the updated list
getUserData();
})
.catch(err => {
console.error('Error appending users:', err);
alert('Error appending users. Check console for details.');
});
};
// Add event listeners
document.getElementById('append-users').addEventListener('click', appendUsers);
// HTML ELEMENT
<button id="append-users">Append Users</button>