I am currently a JavaScript Padawan learner.
After a few hours of trying It would seem that it is not possible to get a value or JSON object returned from a fetch function. Apparently I missed that in the MDN documentation on fetch.
“`
alert(site_rules());
function site_rules(){
fetch(“../conf/rules.json”, {
mode: ‘no-cors’,
cache: ‘no-cache’,
method: “POST”
})
.then(function (response) {
return response.json()})
.then(function (rules) {
return JSON.stringify(rules);
}).catch(function (error) {
console.log(error)
});
}
For me it seems odd to retrieve a JSON file from the server and then be limited to using it only inside the fetch function.
Any insights?
Have a fantastic evening.
W.