-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
69 lines (66 loc) · 1.72 KB
/
index.html
File metadata and controls
69 lines (66 loc) · 1.72 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Test - Czat</title>
<style>
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
.textbox{
width: 100%;
height: 400px;
display: flex;
flex-direction: column;
justify-content: flex-end;
align-items: flex-end;
border: 5px solid black;
}
input{
width: 100%;
padding: 20px;
}
button{
padding: 10px;
}
</style>
</head>
<body>
<h1>Test - Czat</h1>
<div class="textbox"></div>
<input type="text">
<button onclick="test()">Wyślij</button>
</body>
</html>
<script>
const input = document.querySelector("input")
input.addEventListener('keydown', function(event) {
if (event.key === 'Enter') {
test();
}
});
function test(){
const message = input.value;
input.value = "";
textbox = document.querySelector(".textbox");
textbox.innerHTML += `<p>${message}</p>`
fetch("http://127.0.0.1:8000/bartek", { //Tutaj podmień adres API na ten serwerowy
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({ content: message })
})
.then(response => response.json())
.then(data => {
textbox.innerHTML += `<b>${data.content}</b>`
console.log(data);
})
.catch((error) => {
console.error("Error:", error);
});
}
</script>