Javascript Snippet · Simple Status Badge
An example of a tiny widget that could be used to update a status badge on the dashboard without reloading the page:
async function updateStatusBadge() {
const response = await fetch('/api/status.php');
const data = await response.json();
const badge = document.querySelector('[data-status-badge]');
if (!badge) return;
badge.textContent = data.label;
badge.className = 'status-badge status-badge--' + data.state;
}
setInterval(updateStatusBadge, 15000);
updateStatusBadge();
The PHP side would simply return a small JSON object with the current
state, for example {"state": "ok", "label": "All good"}.