33 lines
885 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)
})
async function hello() {
2021-01-25 11:07:52 +01:00
const name = document.querySelector("#name").value
const res = await fetch('api/hello', {
2021-01-24 21:52:41 +01:00
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
2021-01-25 11:07:52 +01:00
body: JSON.stringify({ name })
2021-01-24 21:52:41 +01:00
})
2021-01-25 11:07:52 +01:00
2021-01-24 21:52:41 +01:00
const { message } = await res.json()
2021-01-25 11:07:52 +01:00
2021-01-24 21:52:41 +01:00
alert(message)
}
</script>
</head>
<body>
<label for="name">Name: </label><input id="name" value="World">
<button onclick="hello()">Hello</button>
</body>
</html>