Files

33 lines
898 B
HTML
Raw Permalink Normal View History

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