-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
28 lines (26 loc) · 970 Bytes
/
script.js
File metadata and controls
28 lines (26 loc) · 970 Bytes
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
async function populateTable() {
try {
const response = await fetch(
"https://intruder-alert-system.onrender.com/api/history"
);
console.log(response);
const data = await response.json();
const tbody = document.getElementById("data-table-tbody");
data.forEach((item) => {
const tr = document.createElement("tr");
const str = item.time
const date =str.split(",")[0]
const time =str.split(",")[1]
tr.innerHTML = `
<td class="border px-4 py-2">${item._id}</td>
<td class="border px-4 py-2">${date}</td>
<td class="border px-4 py-2">${time}</td>
<td class="border px-4 py-2">${item.message || "N/A"}</td>
`;
tbody.appendChild(tr);
});
} catch (error) {
console.error("Error fetching data:", error);
}
}
window.onload = populateTable;