[英]CORS Getting No 'Access-Control-Allow-Origin' header is present but OPTIONS and POST request get 200 but
I cannot get a CORS request to work and this is day 4 battling with it. 我无法收到CORS的要求来工作,今天是第4天。 I am getting a 200 on my OPTIONS request and also a 200 on my POST request and all of the headers look like it should work, but I am still getting the error
No 'Access-Control-Allow-Origin' header is present
. 我在OPTIONS请求上收到200,在POST请求上收到200,所有标头看起来都应该正常工作,但是仍然出现错误
No 'Access-Control-Allow-Origin' header is present
。
I am using Laravel (PHP) and the Fetch API in a React app. 我在React应用程序中使用Laravel(PHP)和Fetch API。
Here is a screenshot of my OPTIONS request and the following POST request: 这是我的OPTIONS请求和以下POST请求的屏幕截图:
OPTIONS request 选项要求
What it ended up being was I had dd(variable)
which is a dump and die, in my controller. 最终结果是我的控制器中有
dd(variable)
,这是一个转储而死。 For some reason, this was causing the CORS error, which can be explained better here: look for this comment: davidnknight commented on Sep 26, 2014 由于某种原因,这导致了CORS错误,可以在此处进行更好的解释: 查找此评论:davidnknight于2014年9月26日发表评论
To paraphrase: If your backend is throwing errors or not completing successfully, you will get CORS errors because the correct headers are not being sent. 解释一下:如果后端抛出错误或未成功完成,则将收到CORS错误,因为未发送正确的标头。
So, make sure your backend is working properly. 因此,请确保您的后端工作正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.