I stumbled across an issue where I was trying to parse an incoming .JSON object in an async Fetch-Get request, it gave me the following error in the browser:
Uncaught (in promise) SyntaxError: Unexpected token o in JSON at position 1
at JSON.parse (<anonymous>)
at window.getData (Login.js:32)
at async window.login (Login.js:38
This is the relevant pre-browserified code:
window.getData = async function()
{
var response = await fetch("https://goldengates.club:3000/api/blocks");
var chain = await response.json();
var chainParsed = JSON.parse(chain);
return chainParsed;
}
window.login = async function()
{
const chain = await getData(); //might need to parse this
console.log(chain);
}
The login function above gets called once a button is pressed in the front end.
I am obviously doing something wrong and it's bugging me, I am fairly new to asynch and any help is greatly appreciated.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…