AI-API / templates /index.html
JJ94's picture
Create templates/index.html
a38d127 verified
raw
history blame
1.17 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chatbot</title>
<script>
async function sendMessage() {
const message = document.getElementById("userInput").value;
if (!message) return;
document.getElementById("chatBox").innerHTML += `<p><b>You:</b> ${message}</p>`;
const response = await fetch("/chat", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ message })
});
const data = await response.json();
document.getElementById("chatBox").innerHTML += `<p><b>Bot:</b> ${data.response}</p>`;
document.getElementById("userInput").value = "";
}
</script>
</head>
<body>
<h2>Chatbot</h2>
<div id="chatBox" style="border: 1px solid #000; padding: 10px; width: 50%; height: 300px; overflow-y: scroll;"></div>
<input type="text" id="userInput" placeholder="Type a message..." />
<button onclick="sendMessage()">Send</button>
</body>
</html>