CORS Error
Quick summary
The browser blocked your cross-origin request because the server didn't send the right CORS headers to permit it.
Why this happens
The API is on a different origin and doesn't send
Access-Control-Allow-OriginThe server's CORS policy doesn't include your origin
Credentials mode mismatch (
credentials: 'include'without proper server config)
Minimal example
// Frontend at http://app.com
fetch("http://api.com/data") // blocked by CORS// Server at api.com adds:
// Access-Control-Allow-Origin: http://app.com
fetch("http://api.com/data") // now allowedThe browser blocks the cross-origin request because api.com doesn't send CORS headers — the server must add Access-Control-Allow-Origin to permit the request.
How to diagnose
Check the browser console for the CORS error message
Inspect the response headers in the Network tab — is
Access-Control-Allow-Originpresent?Verify the server's CORS configuration allows your origin
How to fix
Add CORS headers on the server (
Access-Control-Allow-Origin: *or your origin)Use a proxy server to make the request from the same origin
Fix the credentials mode to match the server configuration
How to prevent
Configure CORS properly on your APIs during development
Use same-origin requests or a proxy when possible
Related Resources
Related Practice
- HTTP Methods Quiz
Test your knowledge of HTTP methods used in CORS.
Related Tools
- HTTP Status Codes
Reference for HTTP status codes related to CORS errors.