-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
30 lines (27 loc) · 822 Bytes
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<!DOCTYPE html>
<html>
<head>
<title>FastAPI WebSocket Demo</title>
</head>
<body>
<h1>WebSocket Demo</h1>
<input type="text" id="messageText" placeholder="Type a message...">
<button onclick="sendMessage()">Send</button>
<ul id="messages">
</ul>
<script>
const ws = new WebSocket("ws://localhost:8000/ws");
ws.onmessage = function(event) {
const messages = document.getElementById('messages');
const message = document.createElement('li');
message.textContent = event.data;
messages.appendChild(message);
};
function sendMessage() {
const input = document.getElementById("messageText");
ws.send(input.value);
input.value = '';
}
</script>
</body>
</html>