I try to fetch a json file from remote server, I get syntax error when code is executed from local server, to avoid cors error I set mode: "no-cors"
This is my code:
async function logJSONData() {
const response = await fetch("https://leafpark.city/data/test.json",{
mode: "no-cors", // no-cors, *cors, same-origin
cache: "no-cache", // *default, no-cache, reload, force-cache, only-if-cached
credentials: "same-origin", // include, *same-origin, omit
headers: {
// "Content-Type": "application/json",
'Content-Type': 'application/x-www-form-urlencoded',
},
redirect: "follow", // manual, *follow, error
referrerPolicy: "no-referrer" // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
});
const jsonData = await response.json();
initMap(jsonData);
return(jsonData);
}
let jsonData = logJSONData();
I get this error:
dex.js:120 Uncaught (in promise) SyntaxError: Unexpected end of input
the error is in this line:
const jsonData = await response.json();
Most of my code is copy-pasted from documentation examples from the Fetch API, so I really don't know what's happening.