|
|
|
|
|
const chatOutputContainer = document.querySelector('.chat-output-container');
|
|
|
|
|
|
|
|
|
document.getElementById('myForm').addEventListener('submit', async (e) => {
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
|
const formData = new FormData(e.target);
|
|
|
|
|
|
|
|
|
const questionInput = document.querySelector('input[name="question"]');
|
|
|
const questionText = questionInput.value;
|
|
|
|
|
|
|
|
|
const response = await fetch('/ask', {
|
|
|
method: 'POST',
|
|
|
body: formData,
|
|
|
});
|
|
|
|
|
|
|
|
|
const responseText = await response.text();
|
|
|
|
|
|
|
|
|
const chatOutput = document.querySelector('.chat-output');
|
|
|
const questionHtml = `<div class="question"><h3>${questionText}</h3></div>`;
|
|
|
const responseHtml = `<div class="answer"><h3>${responseText}</h3></div>`;
|
|
|
chatOutput.innerHTML += questionHtml + responseHtml;
|
|
|
}); |