0

I need to access a json file located on a different server (with angular). Naturally I would get a No Access-Control-Allow-Origin.
These are the solution I have tried
Placing an .htaccess in the folder where the file is located with.

<IfModule mod_headers.c>
   <Directory /var/www/app/json>
      <FilesMatch "\.(json|jsonp)$">
         Header set Access-Control-Allow-Origin *
         Header set Access-Control-Allow-Credentials true
      <FilesMatch>
   </Directory>
</IfModule>

The javascript looks like this.

var json = $resource(url,{},{"get":
   {
      "isArray":false,
      "cache":false,
      "responseType":"json",
      "withCredentials":true,
      "headers":{"Access-control-Allow-Origin":"*",'Content-Type': 'application/json'}
   }
});
 json.get(function(data){
    console.log(data);
 });

My issue is similar to this but it has not helped me.

Community
  • 1
  • 1
fredtma
  • 1,007
  • 2
  • 17
  • 27
  • 1
    put Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS" in .htaccess too – wayne Mar 24 '14 at 14:21
  • Thanks @wayne that has solved it, I also removed all the headers that was set in the javascript and it's worked. – fredtma Mar 24 '14 at 14:55

0 Answers0