Get request from script #4630
Answered
by
WantToLearnJapanese
XaverStiensmeier
asked this question in
Q&A
-
I've tried to perform a get request within a script, but fetch never returned. Am I doing something wrong or is it somehow prevented? var url = 'https://ilaris-online.de/api/ilaris/kreatur/';
async function fetchData() {
try {
const response = await fetch(url);
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
const kreaturen = await response.json();
api.log("Test>");
api.log(kreaturen);
} catch (error) {
api.log("Error")
api.log(error)
}
}
api.log("<Test");
fetchData(); results in: TypeError: Failed to fetch. Interestingly enough |
Beta Was this translation helpful? Give feedback.
Answered by
WantToLearnJapanese
Feb 2, 2024
Replies: 1 comment 6 replies
-
I guess you executed it as a frontend script. |
Beta Was this translation helpful? Give feedback.
6 replies
Answer selected by
XaverStiensmeier
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I guess you executed it as a frontend script.
It may be blocked due to CORS policy. Retry after changing it to a backend script.