-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
34 lines (32 loc) · 988 Bytes
/
app.js
File metadata and controls
34 lines (32 loc) · 988 Bytes
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
const btnSend = document.getElementById("btn");
const chat = document.getElementById("chat");
const getMessage = (msg) => {
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
const response = xhr.responseText;
const chatBody = document.querySelector(".scroller");
const divCpu = document.createElement("div");
divCpu.className = "alicia visible";
divCpu.innerHTML = response;
const divUser = document.createElement("div");
divUser.className = "me visible";
divUser.textContent = msg;
chatBody.append(divUser);
setTimeout(() => {
chatBody.append(divCpu);
}, 600);
// console.log(divCpu);
}
};
xhr.open("GET", "bot/chat.php?msg=" + msg, true);
xhr.send();
};
btnSend.addEventListener("click", (e) => {
e.preventDefault();
if (chat.value == "") {
} else {
getMessage(chat.value);
chat.value = "";
}
});