I'm using fetch to get data json from an api. Works fine but I have to use it repeatedly for various calls, thus it needs to be synchronous or else I need some way to update the interface when the fetch completes for each component.
function fetchOHLC(yUrl){
fetch(yUrl)
.then(response => response.json())
.then(function(response) {
alert(JSON.stringify(response.query));
var t = response.created;
var o = response.open;
var h = response.high;
var l = response.low;
var c = response.close;
return {t,o,h,l,c};
})
.catch(function(error) {
console.log(error);
});
}
var fetchData = fetchOHLC(yUrl);
alert(fetchData); // empty ?
Is there any other way to achieve it other than using fetch? (I don't want to use jquery preferrably).
Thanks
Edit
The question is about fetch-api, not ajax, not jquery, so please stop marking it as duplicate of those questions without reading it properly.
chrome.webRequest.onBeforeRequest.addListener
won’t let you do asynchronous operations, leaving you no choice.) – Backlog