@SempervivumJul 17.2022 — #@sibert#1645406 >How do I put values in an outside variable for use in another function?
This is not possible as fetch is working asynchronously. Your function will always return a promise that has to be resolved: ``<i> </i> let body = { method: 'GET', headers: { 'Content-Type': 'application/json' }, };
function chg_status(url, body) { return fetch(url, body) .then(response => response.json()) .then(obj => obj) }; let answer = chg_status("https://api3.go4webdev.org/usr/all", body) answer.then(obj => { console.log(obj); });<i> </i>`` Formerly, at times of XMLHttpRequest, it was possible to switch to sychronous mode but using this was not recommended.
@SempervivumJul 21.2022 — #Yes, when processing is done inside a function, this is possible.
A different option is handing over the function or it's reference to chg_status: ``<i> </i> function chg_status(url, body, callback) { fetch(url, body) .then(response => response.json()) .then(obj => { callback(obj); }) }
function another(answer) { alert(JSON.stringify(answer)) } chg_status("https://api3.go4webdev.org/usr/all", body, another)<i> </i>``