In a React app component which handles Facebook-like content feeds, I am running into an error:
Feed.js:94 undefined \"parsererror\" \"SyntaxError: Un
If anyone else is using fetch from the "Using Fetch" documentation on Web API's in Mozilla: (This is really useful: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch)
fetch(api_url + '/database', {
method: 'POST', // or 'PUT'
headers: {
'Content-Type': 'application/json'
},
body: qrdata //notice that it is not qr but qrdata
})
.then((response) => response.json())
.then((data) => {
console.log('Success:', data);
})
.catch((error) => {
console.error('Error:', error); });
This was inside the function:
async function postQRData(qr) {
let qrdata = qr; //this was added to fix it!
//then fetch was here
}
I was passing into my function qr
what I believed to be an object because qr
looked like this: {"name": "Jade", "lname": "Bet", "pet":"cat"}
but I kept getting syntax errors.
When I assigned it to something else: let qrdata = qr;
it worked.