Habemus frontend

This commit is contained in:
Marce Coll
2021-11-27 13:05:12 +01:00
parent 603e6dba2b
commit 7a8ae86a1c
3 changed files with 32 additions and 5 deletions

View File

@@ -0,0 +1,19 @@
const r = (callback) => window.addEventListener('DOMContentLoaded', callback);
const g = (name) => document.getElementById(name);
r(() => {
g('submit').addEventListener('click', async () => {
const frase = g('frase').value;
const response = await fetch('/calcula', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
'frase': frase
})
})
const resultat = await response.text();
g('response').innerHTML = resultat;
});
})