Tionat_Chatbot2 / script.js
ajaybolloju's picture
Update script.js
2941d26 verified
raw
history blame contribute delete
606 Bytes
async function sendMessage() {
const input = document.getElementById('user-input');
const message = input.value;
if (!message.trim()) return;
const chatBox = document.getElementById('chat-box');
chatBox.innerHTML += `<div class='user'>You: ${message}</div>`;
input.value = '';
const response = await fetch('/chat', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ message })
});
const data = await response.json();
chatBox.innerHTML += `<div class='bot'>Bot: ${data.response}</div>`;
chatBox.scrollTop = chatBox.scrollHeight;
}