-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsendText.js
32 lines (29 loc) · 908 Bytes
/
sendText.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
31
32
document.addEventListener("DOMContentLoaded", () => {
const askButton = document.getElementById("ask");
const questionInput = document.getElementById("question");
askButton.addEventListener("click", () => {
const text = questionInput.value;
if (text.trim() !== "") {
// Send the user's input to the server
sendTextToServer(text);
} else {
alert("Please enter a question.");
}
});
function sendTextToServer(text) {
fetch("/synthesize", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ text: text }),
})
.then((response) => response.text())
.then((data) => {
console.log(data); // Log the server's response
})
.catch((error) => {
console.error("Error:", error);
});
}
});