text-display/public/js/edit.js
2023-02-16 13:35:42 +00:00

17 lines
474 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(location.protocol + '/api/edit', options)
.then((response) => response.text())
.then(data => {
redirectOrNot(data);
})
.catch(err => console.error(err));
}
async function redirectOrNot(res) {
let url = location.protocol
location.href = url+res
}