If anyone else is using fetch from the "Using Fetch" documentation on Web API's in Mozilla:
(This is really useful:
[To see links please register here]
)
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.