base-golang/pkg/sse/client.html

26 lines
483 B
HTML
Raw Normal View History

2024-07-23 10:23:43 +08:00
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Server Sent Event</title>
</head>
<body>
<div id="event-data"></div>
</body>
<script>
const $stream = new EventSource("/stream");
const $log = document.querySelector('#event-data')
$stream.addEventListener("message", function (e) {
log(e.data)
});
function log(msg) {
$log.innerHTML += `<p>消息: ${msg}</p>`
$log.scrollTop += 1000
}
</script>
</html>