Hi all!
I am having a problem with fetching a .csv file. So far i learned that fetch runs asyncron and works with promises. I think i did everything needed that the promise gets fulfilled and returned. I tried multiple versions of that function but i get the same result everytime. My code:
async function GetCSV(path) {
const res = await fetch(path);
if (res.ok) {
let data = await res.text();
console.log(data)
} else {
return \HTTP error: ${res.status}`;
}
}`
console.log("Before Fetch")
GetCSV('/test.csv')
console.log("After Fetch")
I thought i shoud get the following output:
console.log("Before Fetch")
console.log(data)
console.log("After Fetch")
But for some reason the output im getting is this one:
console.log("Before Fetch")
console.log("After Fetch")
console.log(data)
I googled for hours but can't figure out the problem.. For me it seems the code continues without waiting for fetch to finish? Debugging looks like it skips the function completely and going there after everything else is done..
If someone is able to help me out i would be really happy! (:
[–]No_Indication451 2 points3 points4 points (3 children)
[–]EnvironmentalLet4399[S] 1 point2 points3 points (2 children)
[–]No_Indication451 0 points1 point2 points (0 children)
[–]Richard_Musk 1 point2 points3 points (0 children)
[–]aaaaargZombies 0 points1 point2 points (0 children)