17 lines
508 B
JavaScript
17 lines
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
|
||
|
}
|