且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Axios返回请求标头字段X-Requested-With是Access-Control-Allow-Headers不允许的

更新时间:2022-11-12 10:47:20

Laravel使用标头来确定请求是XHR还是常规请求.

Laravel uses a header to be able to determine wether a request was XHR or a normal request.

在Laravel的源代码中,您可以看到 Symfony中的 isXmlHttpRequest() 方法.

In the source code of Laravel you can see the Request::ajax() method, which calls the isXmlHttpRequest() method from Symfony.

唯一的问题是,CORS并不真的喜欢这样的标头.

The only issue with this is that CORS doesn't really like such headers.

如果要删除它,请检查 resources/js 中的 bootstrap.js 并再次编译资产.

If you want to remove it, check bootstrap.js in resources/js and compile your assets again.

另一种解决方案是在调用之前删除标头:

Another solution would be to delete the header just before the call:

删除axios.defaults.headers.common ['X-Requested-With'];