generated from ElnuDev/go-project
Implent SSE feed
This commit is contained in:
parent
3a8179a99a
commit
b5ca22cd7d
2 changed files with 2 additions and 3 deletions
2
main.go
2
main.go
|
@ -48,7 +48,7 @@ func generateCounter() handler {
|
|||
case <-ctx.Done():
|
||||
break outer
|
||||
case <-tick:
|
||||
fmt.Fprintf(w, "event: count\ndata: %d\n\n", i)
|
||||
fmt.Fprintf(w, "event: count\ndata: <div>%d</div>\n\n", i)
|
||||
w.(http.Flusher).Flush()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,8 +7,7 @@
|
|||
<script src="https://unpkg.com/htmx.org@1.9.3"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div hx-sse="connect:/api/counter">
|
||||
<div hx-sse="swap:count"></div>
|
||||
<div hx-sse="connect:/api/counter swap:count" hx-swap="beforebegin">
|
||||
</div>
|
||||
<button hx-get="/api/click1" hx-swap="innerHTML">Click me!</button>
|
||||
<br>
|
||||
|
|
Reference in a new issue