Files
wasm-http-server/docs/hello-state-keepalive/index.html
2025-11-21 01:04:46 +01:00

33 lines
898 B
HTML

<!DOCTYPE html>
<html>
<head>
<title>go-wasm-http-server hello with state and keepalive demo</title>
<script>
navigator.serviceWorker.register('sw.js').then((registration) => {
const sw = registration.active ?? registration.installing ?? registration.waiting;
setInterval(() => sw.postMessage(null), 15000);
});
async function hello() {
const name = document.querySelector('#name').value;
const res = await fetch('api/hello', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ name }),
});
const { message } = await res.json();
alert(message);
}
</script>
</head>
<body>
<label for="name">Name: </label><input id="name" value="World" />
<button onclick="hello()">Hello</button>
</body>
</html>