Level 73
You can use the fetch API to fetch the new data from the server, then parse it into a table body and replace the table body.
async function getRequest(url, parameters = {}) {
try {
let responsePromise = await fetch(url, { method: 'GET', headers: parameters});
if(! responsePromise.ok) {
throw new Error(responsePromise.status );
}
return await responsePromise.json();
} catch (error) {
return error;
}
}
async function refreshTable() {
let response = getRequest('/api/v1/table-api');
let tbody = '';
response.items.forEach((item) => {
tbody += `<tr><td>${item.field1}</td><td>${item.field2}</td></tr>`;
});
document.querySelector('#table-body').innerHTML = tbody;
}