-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
32 lines (26 loc) · 1.03 KB
/
script.js
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
function sendMessage() {
const userInput = document.getElementById('userInput');
const chatMessages = document.getElementById('chatMessages');
if (userInput.value.trim() !== "") {
const userMessage = document.createElement('div');
userMessage.classList.add('message', 'user-message');
userMessage.textContent = userInput.value;
chatMessages.appendChild(userMessage);
const botMessage = document.createElement('div');
botMessage.classList.add('message', 'bot-message');
console.log(userInput.value);
fetch("/Stues", {
method: 'POST',
headers: { 'Content-Type': 'text/plain' },
body: userInput.value
}).then(response => {
return response.text()
}).then(botAnswer => {
botMessage.textContent = botAnswer;
}).then(()=>{
chatMessages.appendChild(botMessage);
})
userInput.value = "";
chatMessages.scrollTop = chatMessages.scrollHeight;
}
}