AngularJS 没有检测到 Access-Control-Allow-Origin header ?

标签 angularjs angularjs-http

我在本地虚拟主机 ( http://foo.app:8000 ) 上运行一个 angular 应用程序。它正在使用 $http.post 向另一个本地 VirtualHost ( http://bar.app:8000 ) 发出请求.

$http.post('http://bar.app:8000/mobile/reply', reply, {withCredentials: true});

在 Chrome 开发者工具的 Network 选项卡中,我当然会看到 OPTIONS 请求,响应包括标题:
Access-Control-Allow-Origin: http://foo.app:8000

但是,POST 请求被取消并出现以下错误:

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



有没有人经历过这个? Access-Control-Allow-Origin header 非常清楚地包含在 OPTIONS 请求的响应中,所以我一生都无法弄清楚为什么 POST 会导致 header 丢失。
Access-Control-Allow-Credentials也设置为 true .

最佳答案

这是本地开发人员在 chrome 中的一个错误。尝试其他浏览器。然后它会起作用。

关于AngularJS 没有检测到 Access-Control-Allow-Origin header ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21102690/

相关文章:

javascript - 基于 div 宽度的动态文本长度限制

angularjs - 如何模拟一个 Angular $http 调用并返回一个行为类似于 $http 的 promise 对象

javascript - angularjs 国家代码通过 $http 请求从 jsonfile 中查找

javascript - 为什么我得到错误 : http. get is not a function

javascript - 输入类型= angularjs中的数字验证

javascript - Angularjs - json内容不显示

javascript - AngularJS 向 $http.get 添加 header

angularjs - 不要使用 ng-model 记录无效值

javascript - AngularJS 中出现 CORS 错误

angularjs - Angular Js - 在 header 默认设置 token