localhost上的CORS错误:9000 angularjs

时间:2015-03-20 16:31:42

标签: angularjs cors

在本地运行app时,我收到以下错误:

SCRIPT7002: XMLHttpRequest: Network Error 0x80070005, Access is denied.

SEC7120: Origin http://localhost:9000 not found in Access-Control-Allow-Origin header.

但是,在服务器上部署时,它可以正常工作。你能帮忙吗?

提前致谢。

1 个答案:

答案 0 :(得分:0)

尝试将它们添加到配置

,将它们添加到标题中
 myApp.config({
      $httpProvider.defaults.useXDomain = true;
      delete $httpProvider.defaults.headers.common["X-Requested-With"];
      $httpProvider.defaults.headers.common["Accept"] = "application/json";
      $httpProvider.defaults.headers.common["Content-Type"] = "application/json";
      $httpProvider.defaults.headers.common['Access-Control-Allow-Origin'] = '*';
      $httpProvider.defaults.headers.common['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept';
      $httpProvider.defaults.headers.common['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS, PUT';
      $httpProvider.defaults.headers.common['Access-Control-Allow-Credentials'] = true;
      });