Parse response with .json() within fetch callback.

This commit is contained in:
mmcwilliams 2017-11-21 16:49:02 -05:00
parent c402e6e87d
commit 550dad4c91
1 changed files with 9 additions and 2 deletions

View File

@ -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;