1

I was building an Angular2 app and use http.get to get JSON data.

The issue is that for a local file, it is working perfectly.

this.http.get('data.json').map((res:Response) => res.json())

But I am not able to get anything when the url is external. The url has permissions for GET. There is not even a GET request being shown in the console messages.

Moreover, if I try to do GET Request on this same url in nodejs using a library like 'request', it works fine too. Can I know what are the possible reasons for the same?

gopher kri
  • 43
  • 4
  • 2
    Sounds like a CORS issue for me. http://stackoverflow.com/questions/36768418/how-to-make-cors-enabled-http-requests-in-angular-2 – Danscho Nov 27 '16 at 18:51
  • Try to install this chrome app : https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi it should work. IF it work, it's a CORS issue as Danscho said. (it's a powerful extension, be careful with that and don't forget to toggle it off once you're done). – maxime1992 Nov 27 '16 at 18:53
  • Oh, thanks a lot. Now it works and I can stop banging my head. I will fix the CORS issue then on the server side. – gopher kri Nov 27 '16 at 19:02

0 Answers0