i am getting error when using fetch api to fetch quotes this project is working fine locally but when i deploy it , it shows error → SyntaxError: Unexpected token ‘<’, "<!DOCTYPE "… is not valid JSON
this is the link to the site on netlify
https://golden-sorbet-6ef88a.netlify.app/
I am faced this issue previously too … i would really appreciate your help
Hey @YashhSingh
The first issue I see is the URL used in the fetch
request
const data = await fetch('https:type.fit/api/quotes');
which should look like
const data = await fetch('https://type.fit/api/quotes');
hey coelmay man it worked! thanks alot , but i have one more question what’s wrong with that first link i got this link from freecodecamp and it worked fine locally and what happened in the second link when we gave this // so what is the catch here ? and does this logic applies to all links when i deploy them ? I serious doubt here
When linking to or referencing an external resource (i.e. on another domain) all links need a //
such as
<a href="https://example.com">Example</a>
or
await fetch('https://api.example.com`)
In some cases you can drop the http:
or https:
and have e.g.
<img src="//example.com/logo.png">
If the resource is part of the site you could use
<img src="/img/logo.png">
or
<a href="/about">About Page</a>
For a more in-depth explanation checkout
1 Like