2021-01-22 15:54:33 +01:00
|
|
|
<!DOCTYPE html>
|
|
|
|
|
<html>
|
|
|
|
|
<head>
|
|
|
|
|
<title>go-wasm-http-server hello with state demo</title>
|
|
|
|
|
<script>
|
2025-11-21 00:57:18 +01:00
|
|
|
navigator.serviceWorker.register('sw.js');
|
2021-01-22 15:54:33 +01:00
|
|
|
|
|
|
|
|
async function hello() {
|
2025-11-21 00:57:18 +01:00
|
|
|
const name = document.querySelector('#name').value;
|
2021-01-25 11:07:52 +01:00
|
|
|
|
|
|
|
|
const res = await fetch('api/hello', {
|
2021-01-22 15:54:33 +01:00
|
|
|
method: 'POST',
|
|
|
|
|
headers: {
|
2025-11-21 00:57:18 +01:00
|
|
|
'Content-Type': 'application/json',
|
2021-01-22 15:54:33 +01:00
|
|
|
},
|
2025-11-21 00:57:18 +01:00
|
|
|
body: JSON.stringify({ name }),
|
|
|
|
|
});
|
2021-01-25 11:07:52 +01:00
|
|
|
|
2025-11-21 00:57:18 +01:00
|
|
|
const { message } = await res.json();
|
2021-01-25 11:07:52 +01:00
|
|
|
|
2025-11-21 00:57:18 +01:00
|
|
|
alert(message);
|
2021-01-22 15:54:33 +01:00
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
</head>
|
|
|
|
|
<body>
|
2025-11-21 00:57:18 +01:00
|
|
|
<label for="name">Name: </label><input id="name" value="World" />
|
2021-01-22 15:54:33 +01:00
|
|
|
<button onclick="hello()">Hello</button>
|
|
|
|
|
</body>
|
|
|
|
|
</html>
|