Today We are Going To Solve Access to XMLHttpRequest has been blocked by CORS policy Redirect is not allowed for a preflight request only one route in laravel. Here we will Discuss All Possible Solutions and How this error Occurs So let’s get started with this Article.
Contents
How to Fix Access to XMLHttpRequest has been blocked by CORS policy Redirect is not allowed for a preflight request only one route Error?
- How to Fix Access to XMLHttpRequest has been blocked by CORS policy Redirect is not allowed for a preflight request only one route Error?
To Fix Access to XMLHttpRequest has been blocked by CORS policy Redirect is not allowed for a preflight request only one route Error just Run the commands. Just install the core by following command:
npm install cors
The require cors.var cors = require('cors')
Then, You have to just add it as a middleware to your app.app.use(cors())
And your error will be removed. - Access to XMLHttpRequest has been blocked by CORS policy Redirect is not allowed for a preflight request only one route
To Fix Access to XMLHttpRequest has been blocked by CORS policy Redirect is not allowed for a preflight request only one route Error just Be aware of trailing slash. Here your error is coming from Vue app just like below example of your url
https://example.com/api/methods/
And the backend redirect it to:https://example.com/api/methods
So here you have to be aware of the trailing slash at the end. and your error will be removed. So try this.
Solution 1 : Run the commands
Just install the core by following command:
npm install cors
The require cors.
var cors = require('cors')
Then, You have to just add it as a middleware to your app.
app.use(cors())
And your error will be removed.
Solution 2 : Be aware of trailing slash
Here your error is coming from Vue app just like below example of your url
https://example.com/api/methods/
And the backend redirect it to:
https://example.com/api/methods
So here you have to be aware of the trailing slash at the end. and your error will be removed. So try this.
Conclusion
So these were all possible solutions to this error. I hope your error has been solved by this article. In the comments, tell us which solution worked? If you liked our article, please share it on your social media and comment on your suggestions. Thank you.
Also Read This Solutions
- For your account security logging into Facebook from an embedded browser is disabled.
- FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed – JavaScript heap out of memory in ionic 3
- ImportError: cannot import name ‘json’ from ‘itsdangerous’
- Root composer.json requires php ^7.3 but your php version (8.0.0) does not satisfy that requirement in laravel
- remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead