Uncaught (in promise) SyntaxError: Unexpected end of JSON input
getting this error when using fetch to connect to my rails api
fetch(`/products/${dataid}/description`)
.then(res=>res.json())
.then(json=>console.log(json))
in the browser I was able to get to the page
http://127.0.0.1:3000/products/11/description
answer
rails action was rendering basic text not json, so I had to change fetch
***Rails
def description
product=Product.find(params[:id])
if product
if product.description
render plain: product.description
else
render plain: “No description”
end end end
***JS
fetch(`/products/${dataid}/description`)
.then(res=>res.text()) //<————————————-
.then(json=>console.log(json))