Javascript AngularJS“否”访问控制允许来源“头出现在请求的资源上”错误
我使用的是AngularJS 1.2.20 每当我使用$http服务从不同域/服务器的URL访问zip文件时,都会出现如下错误: 无法加载XMLHttpRequesthttp://localhost/ABC/updates.zip. 请求的资源上不存在“Access Control Allow Origin”标头。起源'http://localhost:8080因此,不允许访问 我已尝试在模块的配置中设置以下内容:Javascript AngularJS“否”访问控制允许来源“头出现在请求的资源上”错误,javascript,angularjs,cors,angular-http,Javascript,Angularjs,Cors,Angular Http,我使用的是AngularJS 1.2.20 每当我使用$http服务从不同域/服务器的URL访问zip文件时,都会出现如下错误: 无法加载XMLHttpRequesthttp://localhost/ABC/updates.zip. 请求的资源上不存在“Access Control Allow Origin”标头。起源'http://localhost:8080因此,不允许访问 我已尝试在模块的配置中设置以下内容: $httpProvider.defaults.useXDomain = true
$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";
但这仍然会带来错误
我的代码片段是:
$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")
});
应如何防止这种情况发生?除非服务器提供API,或允许配置“访问控制允许原始响应”属性,否则除了请求服务器请求ZIP文件外,您无法执行任何操作,因为浏览器不允许这样做