-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
32 lines (32 loc) · 1.05 KB
/
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
31
32
<!DOCTYPE html>
<html>
<head>
<title>Chat</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
</head>
<body>
<input type="text" name="text" id="username" value="Guest">
<input type="text" name="text" id="text">
<input type="button" id="btn" value="Send" onClick="send()" />
<p id="chat"></p>
<script>
loopMessages()
function loopMessages() {
$.get("/chat", function(data, status) {
document.getElementById("chat").innerHTML = `${data}`
});
setTimeout(() => {
loopMessages()
}, 500)
}
function send() {
if (document.getElementById("username").value !== "") {
if (document.getElementById("text").value !== "") {
$.get("/send?message=" + encodeURIComponent(document.getElementById("username").value + " | " + document.getElementById("text").value), function(data, status) {});
document.getElementById("text").value = ""
}
}
}
</script>
</body>
</html>