I have created REST API on server and provided URL to other users.. It returns JSON file when requested from browser address. BUT While using that API in html page with AngularJS provided an error 'No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.'
Asked
Active
Viewed 31 times
1 Answers
0
You should enable CORS in your REST API

DvTr
- 347
- 1
- 5
-
@DvTr..Any link..How can i do that? Actually i was confused as I can acess JSON file as response when I type API URL in address bar. But got issue with AngularJS :( – RahulS Nov 06 '17 at 18:50
-
Which server you use? Anyway, its no nore than add accept-* headers to your requests responses. Depending on how you had created your API, you can add that headers by code as well. – DvTr Nov 06 '17 at 18:52
-
My rest api server is tomcat with SSL..It returns JSON file when called....I want to know syntax of response to return json file. Do you have any links where i can get to know about returning 'response' in java. Thanks :) – RahulS Nov 06 '17 at 19:06
-
Its not the JSON body the problem, but the response headers for the Cross Origin protection, for the OPTIONS verb. You should search for 'Enabling CORS in apache tomcat'. If youre using JAX-RS or Spring, you can add them by code in an interceptor or filter. – DvTr Nov 06 '17 at 19:20