0

I am using 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:

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?

Temp O'rary
  • 5,366
  • 13
  • 49
  • 109

1 Answers1

0

Unless the server provides a JSONP API, or allows configuring the Access-Control-Allow-Origin response attribute, you can't do anything besides requesting that your server requests the ZIP file, as the browser won't allow it.

Bruno Kim
  • 2,300
  • 4
  • 17
  • 27