0

AngularJS 1.2.20 を使用しています。

このサービスを使用し$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.

モジュールの構成で次のように設定しようとしました:

$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")
});

これを防ぐために何をすべきですか?

4

1 に答える 1

0

サーバーがJSONP API を提供するか、Access-Control-Allow-Origin 応答属性の構成を許可しない限り、ブラウザーが許可しないため、サーバーが ZIP ファイルを要求するように要求する以外に何もできません。

于 2014-08-24T21:25:25.913 に答える