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 }