JavaScript fetch() Fails: 'Failed to Fetch' and Network Errors Explained
Find out whether the cause is CORS, a wrong URL, mixed content, a blocked request or the server.
Reference guide. This guide is written from established practice and the official documentation of the tools involved. We have not yet tested every step on a live demo site. Back up your site before you change anything.
TypeError: Failed to fetch is a generic message. Find the real reason in the Network tab.
Check
- Wrong URL or typo, or an address that is not reachable from the visitor's network.
- CORS: see our CORS guide.
- Mixed content: an https page calling an http address is blocked. See our mixed content guide.
- Certificate problems on the API. See our SSL guide.
- Blocked by an extension or firewall.
- Server errors: look at the status code and body. See our status code guide.
Code tips
Always check response.ok, and catch errors:
fetch(url).then(r => { if (!r.ok) throw new Error(r.status); return r.json(); }).catch(console.error);
Tools
See our console guide.
Related guides
- YouTube Video Embed Not Working or Showing an Error on Your Website
- WordPress XML Sitemap Gives 404 or Is Not Generating
- Changed the WordPress Address (URL) and Now the Site or Login Is Broken
- wp-config.php Explained: The Settings That Matter and How to Edit Them Safely
Did this solve it? If not, email hello@sitefixlab.org with the exact error text and we will look into it. Try the problem finder.