angularjs - 请求的资源上不存在 'Access-Control-Allow-Origin' header 。因此不允许访问 Origin 'http://localhost'

标签 angularjs symfony http-headers cors

我在 AngularJS( ionic 框架)中有一个应用程序,在 Symfony 中有一个服务器。

在本地一切正常,但现在我使用在线服务器进行测试。不幸的是,一切都不像本地那样发生,我有以下错误:

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http: // localhost' is therefore not allowed access.

我想知道如何添加缺少的“Access-Control-Allow-Origin”CORS header 。

最佳答案

使用这个包:NelmioCorsBundle

CORS-Bundle 用于定义 CORS 规则。该 bundle 允许您定义哪些域可以访问您的 REST API。它也会让你的工作更轻松 :)

关于angularjs - 请求的资源上不存在 'Access-Control-Allow-Origin' header 。因此不允许访问 Origin 'http://localhost',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43677015/

相关文章:

angularjs - AngularJS 和 Typescript 应用程序的 VSCode gulpfile.js 和 tsconfig.json

Symfony2 - 环境 - 无法从公共(public)文件夹导入 routing.yml

javascript - Chrome 和 Firefox POST 调用的内容类型差异

symfony - 如何在 symfony 中监听控制台事件?

javascript - React - TypeError : this. props.courses.map 不是函数

http - Logstash配置: http output with Base 64 encoded headers

javascript - 如何在 ngMaterial md-autocomplete 中过滤查询?

javascript - 与excel的数字除以千位完全一样的js函数

javascript - Angular - 如何在点击标记后让谷歌地图显示数据库中的名称

php - Symfony 的可空自定义表单实体