text-display/public/js/edit.js
2023-02-16 13:30:06 +01:00

17 lines
No EOL
508 B
JavaScript

function saveText() {
let x = document.getElementById("text").value;
const options = {method: 'POST', body: JSON.stringify({text: x}), headers: { 'Content-Type': 'application/json' }};
fetch('http://127.0.0.1:8000/api/edit', options)
.then((response) => response.text())
.then(data => {
redirectOrNot(data);
})
.catch(err => console.error(err));
}
async function redirectOrNot(res) {
let url = "http://" + location.hostname + ":" + location.port
location.href = url+res
}