简体   繁体   English

AngularJS'所请求的资源上没有'Access-Control-Allow-Origin'标头'错误

[英]AngularJS 'No 'Access-Control-Allow-Origin' header is present on the requested resource' error

I am using AngularJS 1.2.20. 我正在使用AngularJS 1.2.20。

Whenever I use the $http service to access a zip file from a URL (different domain/server), it gives me an error as following: 每当我使用$http服务从URL(不同的域/服务器)访问zip文件时,都会出现以下错误:

XMLHttpRequest cannot load http://localhost/ABC/updates.zip. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.

I've tried setting the following in the config of my module: 我尝试在模块的配置中设置以下内容:

$httpProvider.defaults.useXDomain = true;
$httpProvider.defaults.withCredentials = true;
delete $httpProvider.defaults.headers.common["X-Requested-With"];
$httpProvider.defaults.headers.common["Accept"] = "application/json";
$httpProvider.defaults.headers.common["Content-Type"] = "application/json";

But this still throws the error. 但这仍然引发错误。

My code snippet is : 我的代码段是:

$http({method: 'GET', url: paths.categoryUpdateURL}).
success(function(data, status, headers, config) {
    // this callback will be called asynchronously
    // when the response is available
    alert("download Complete")
}).
error(function(data, status, headers, config) {
    // called asynchronously if an error occurs
    // or server returns response with an error status.
    alert("error")
});

What should be done to prevent this? 应该采取什么措施来防止这种情况?

除非服务器提供JSONP API或允许配置Access-Control-Allow-Origin响应属性,否则除非请求服务器请求ZIP文件,否则您将无能为力,因为浏览器不允许这样做。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AngularJS:所请求的资源上不存在“ Access-Control-Allow-Origin”标头 - AngularJS: No 'Access-Control-Allow-Origin' header is present on the requested resource 错误在请求的资源上没有“ Access-Control-Allow-Origin”标头 - Error No 'Access-Control-Allow-Origin' header is present on the requested resource No 'Access-Control-Allow-Origin' header is present on the requested resource error - No 'Access-Control-Allow-Origin' header is present on the requested resource error AngularJS:所请求的资源上不存在“ Access-Control-Allow-Origin”标头。 因此,不允许访问原始“空” - AngularJS : No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access 跨源资源错误:请求的资源上没有“Access-Control-Allow-Origin”标头 - Cross Origin Resource Error: No 'Access-Control-Allow-Origin' header is present on the requested resource Javascript-所请求的资源上没有“ Access-Control-Allow-Origin”标头 - Javascript - No 'Access-Control-Allow-Origin' header is present on the requested resource 请求的资源上不存在“Access-Control-Allow-Origin”标头 - No 'Access-Control-Allow-Origin' header is present on the requested resource 角度4-所请求的资源上没有“ Access-Control-Allow-Origin”标头 - Angular 4 - No 'Access-Control-Allow-Origin' header is present on the requested resource NodeJ在所请求的资源上不存在“ Access-Control-Allow-Origin”标头 - NodeJs No 'Access-Control-Allow-Origin' header is present on the requested resource Access-Control-Allow-Origin header 存在于请求的资源上 - Access-Control-Allow-Origin header is present on the requested resource
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM