So I managed to make my first API accessible locally. However when I try to fetch data like I would normally (URL to phpscript to get data from db), I only get a Response telling me that I was successfully redirected. In which way should I change my fetch function to make this work?
script.js
async function getTop10() {
let url = 'http://192.168.2.131:81/stern';
try {
let res = await fetch(url);
console.log(res);
return await res.json();
} catch (error) {
console.log(error);
}
}
getTop10();
Response
Response {type: 'cors', url: 'http://192.168.2.131:81/stern/', redirected: true, status: 200, ok: true, …}
body: (...)
bodyUsed: true
headers: Headers {}
ok: true
redirected: true
status: 200
statusText: "OK"
type: "cors"
url: "http://192.168.2.131:81/stern/"
[[Prototype]]: Response
Sample dataset from the url
[
[
"Nach",
20
],
[
"In",
16
],
[
"Sie",
15
],
[
"Die",
14
],
[
"So",
10
],
[
"Putin",
10
],
[
"Das",
9
],
[
"Ukraine",
9
],
[
"Deutschland",
9
],
[
"Der",
8
]
]
const getTop10 = async () => {
let url = 'http://192.168.2.131:81/stern';
try {
const res = await fetch(URL);
const data = await res.json();
console.log(data);
} catch (error) {
console.log(error);
}
}
getTop10();