1234567891011121314151617181920212223242526 |
- <!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>
|