37 lines
1.1 KiB
HTML
37 lines
1.1 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<body>
|
|
|
|
<h1>User List</h1>
|
|
<ul id="userList"></ul>
|
|
|
|
<script>
|
|
document.addEventListener("DOMContentLoaded", function () {
|
|
// Fetch the user list from the API
|
|
fetch('/web-api/users')
|
|
.then(response => {
|
|
// Check if HTTP status code indicates success
|
|
if (!response.ok) {
|
|
return Promise.reject('Failed to fetch users');
|
|
}
|
|
return response.json(); // Parse the JSON response
|
|
})
|
|
.then(data => {
|
|
// Display the users on the page
|
|
const userList = document.getElementById('userList');
|
|
data.forEach(user => {
|
|
const li = document.createElement('li');
|
|
li.textContent = `${user.name} (${user.email})`;
|
|
userList.appendChild(li);
|
|
});
|
|
})
|
|
.catch(error => {
|
|
console.error('Error:', error);
|
|
alert('Failed to fetch users');
|
|
});
|
|
});
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|