Parse response with .json() within fetch callback.
This commit is contained in:
parent
c402e6e87d
commit
550dad4c91
|
@ -410,7 +410,7 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
web.setDir = function () {
|
web.setDir = function () {
|
||||||
const dir = !document.getElementById('dir').checked;
|
const dir = document.getElementById('dir').checked;
|
||||||
/*$.ajax({
|
/*$.ajax({
|
||||||
method : 'POST',
|
method : 'POST',
|
||||||
url : '/dir',
|
url : '/dir',
|
||||||
|
@ -423,7 +423,14 @@
|
||||||
method : 'POST',
|
method : 'POST',
|
||||||
body : { dir : dir}
|
body : { dir : dir}
|
||||||
};
|
};
|
||||||
fetch('/dir', opts).then(web.setDirSuccess);
|
fetch('/dir', opts)
|
||||||
|
.then(res => {
|
||||||
|
return res.json()
|
||||||
|
})
|
||||||
|
.then(web.setDirSuccess).catch(err => {
|
||||||
|
console.error('Error setting direction')
|
||||||
|
console.error(err);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
web.setDirSuccess = function (res) {
|
web.setDirSuccess = function (res) {
|
||||||
STATE.dir = res.dir;
|
STATE.dir = res.dir;
|
||||||
|
|
Loading…
Reference in New Issue