close

[Fixed] Access to XMLHttpRequest has been blocked by CORS policy Redirect is not allowed for a preflight request only one route

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.

How to Fix Access to XMLHttpRequest has been blocked by CORS policy Redirect is not allowed for a preflight request only one route Error?

  1. 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.

  2. 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

Leave a Comment