【发布时间】:2017-12-01 07:42:14
【问题描述】:
我在通过 Post 方法从表单发送数据时遇到问题(我使用的是 Angular 4)。我收到以下错误:
XMLHttpRequest cannot load http://ventas.dev/api/register. 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:4200' is therefore not allowed access.
我在应用程序中添加了“Cors”,因此,使用 Postman 我可以创建新用户
我已将我的代码上传到 Gist,以便任何想帮助我的人更轻松。
https://gist.github.com/rickymuvel/806a0ebf37b182ea509d229642914d9f
任何帮助,非常感谢。
【问题讨论】:
-
您可以尝试将内容类型添加到您的标题中吗? {'Content-Type', 'application/x-www-form-urlencoded'}
-
我刚做了,但出现同样的错误。
-
你确定ventas.dev/api/register 启用了cors吗?
标签: angular laravel-5 xmlhttprequest cors