Files
2024-08-18 14:44:26 -07:00

87 lines
2.6 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Data Table</title>
<style>
body {
font-family: Arial, sans-serif;
}
table {
width: 100%;
border-collapse: collapse;
margin: 20px 0;
}
th, td {
border: 1px solid #ddd;
padding: 12px;
text-align: left;
}
th {
background-color: #f2f2f2;
color: #333;
}
tr:nth-child(even) {
background-color: #f9f9f9;
}
tr:hover {
background-color: #f1f1f1;
}
a {
color: #007bff;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<h1>Data Table</h1>
<table id="dataTable">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Set</th>
<th>Number</th>
<th>Quantity</th>
<th>Condition</th>
<th>Language</th>
<th>Image URL</th>
</tr>
</thead>
<tbody>
<!-- Data will be inserted here -->
</tbody>
</table>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', () => {
fetch('/data')
.then(response => response.json())
.then(data => {
console.log('Data fetched from server:', data);
const tableBody = document.querySelector('#dataTable tbody');
data.forEach(item => {
const row = document.createElement('tr');
row.innerHTML = `
<td>${item._id}</td>
<td>${item.name}</td>
<td>${item.set}</td>
<td>${item.number}</td>
<td>${item.quantity}</td>
<td>${item.condition}</td>
<td>${item.language}</td>
<td><a href="${item.image_url}" target="_blank">Image</a></td>
`;
tableBody.appendChild(row);
});
})
.catch(error => console.error('Error fetching data:', error));
});
</script>
</body>
</html>