Currently, I am using Fetch to send a post request to my server while including some additional information. Here's the code snippet:
var rating = document.getElementById("rating");
var ratingValue = rating.innerHTML;
fetch("/films",{
method: "post",
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
body: JSON.stringify({
rated : ratingValue
})
})
However, upon trying to retrieve this data on my server, an error is encountered:
Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0
The corresponding server-side code looks like this:
app.post("/films", function(req,res){
var rating = req.body.rated;
...
})
The issue seems to arise from the first line within the function, specifically when declaring the rating
variable.