CORS error No 'Access-Control-Allow-Origin' header is present on the requested resource
Problem
Hello, this is my request: ` axios({ method: 'POST', url: `${SERVER_ADDRESS}/api/v1/manager/restaurant/${restaurantName}/payment-methods`, crossDomain: true, data: { payment_methods: checkedPayments }, }) .then(() => { dispatch(loadPayments(restaurantName)); }).catch((error) => { console.log(error); dispatch(paymentsError()); }); ` the server is laravel 5, it is responding with: `XMLHttpRequest cannot load http://localhost:8000/api/v1/manager/restaurant/accusamus/payment-methods. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.` Server headers are set with CORS middleware like this: return $next($request) ->header("Access-Control-Expose-Headers", "Access-Control-") ->header("Access-Control-Allow-Headers", "Access-Control-, Origin, X-Requested-With, Content-Type, Accept") ->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS, HEAD') ->header('Access-Control-Allow-Origin', '') ->header('Allow', 'GET, POST, PUT, DELETE, OPTIONS, HEAD'); Theese are the response headers, which I get when I use postman: Access-Control-Allow-Headers →Access-Control-, Origin, X-Requested-With, Content-Type, Accept Access-Control-Allow-Methods →GET, POST, PUT, DELETE, OPTI
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Solution: CORS error No 'Access-Control-Allow-Origin' header is present on the requested resource
My server added `Access-Control-Allow-Origin` header to options request. still get the error. And it's strange that axios actually received 200 & the data server returned. Don't know why I still get the error.
Trust Score
9 verifications
- 1
My server added `Access-Control-Allow-Origin` header to options request.
My server added `Access-Control-Allow-Origin` header to options request.
- 2
And it's strange that axios actually received 200 & the data server returned. Do
And it's strange that axios actually received 200 & the data server returned. Don't know why I still get the error.
Validation
Resolved in axios/axios GitHub issue #569. Community reactions: 120 upvotes.
Verification Summary
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep