gorilla-test2 / static /script.js
gmerrill
update
301ea74
raw
history blame
910 Bytes
const textGenForm = document.querySelector('.text-gen-form');
const translateText = async (text) => {
const response = await fetch(
`query_gorilla`,
{
method: 'POST',
headers: {
"Content-Type": "application/json",
},
body: text
}
);
const responseJSON = await response.json();
return JSON.stringify(responseJSON);
};
textGenForm.addEventListener('submit', async (event) => {
event.preventDefault();
const textGenInput = document.getElementById('text-gen-input');
const textGenParagraph = document.querySelector('.text-gen-output');
try {
textGenParagraph.textContent = "Awaiting response ...";
const txtResp = await translateText(textGenInput.value);
console.info(txtResp);
textGenParagraph.textContent = JSON.stringify(JSON.parse(txtResp).val, null, 2);
} catch (err) {
console.error(err);
}
});