Unable to call Restful Service in AngularJs application - angularjs

I am trying to create a search application in angularjs.However, i am getting the below error . Can someone please help.
AddrBook.html:1 XMLHttpRequest cannot load http://121.242.159.36:6006/AddressBookWS/rest/addressBookService/getCompany/%20%20%20%20%20%20%20%20%20%20JB. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
Thanks
Srikala

(1)
No 'Access-Control-Allow-Origin' header is present on the requested resource.
You are making a cross domain request and this header must be present on the server's response.
The header should be ...
Access-Control-Allow-Origin: *
To allow any domain to make a request to the server.
This is your problem! If you have control over the server then add the response header. If not then make the request at your backend to circumvent the X-domain policy and then make the data available to your angular app.
...
(2)
Origin 'null' is therefore not allowed access -- This is because you are not setting the Origin header in your HTTP request
You can set default headers for all http requests in your app config.
Although (2) will not fix the issue just an FYI.

Related

Getting Cross Origin when trying to add g-reCaptcha in angular

I am getting this error.
XMLHttpRequest cannot load https://www.google.com/recaptcha/api/siteverify. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:9001' is therefore not allowed access. The response had HTTP status code 405.
This is an extra security step for the server to ensure requests coming from clients are legitimate. Otherwise a client could fake a response and the server would be blindly trusting that the client is a verified human.
Use following google chrome extension:
Google chrome extension

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access

I have an application in AngularJS (ionic framework), and a server in Symfony.
In local everything works, but now I do my tests with the server online. Unfortunately everything does not happen like local, I have the following error:
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http: // localhost' is therefore not allowed access.
I was wondering how to add the "Access-Control-Allow-Origin" CORS header that is missing.
Use this bundle: NelmioCorsBundle
The CORS-Bundle is used to define the CORS rules. This bundle allows you to define which domains will have access to your REST API. And it will make your job easier too :)
I don't think your issue came from Angular, it looks like it comes from your API server.
You may need some headers server side:
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Content-Type
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS

Getting CORS error in AngularJS when accessing data form REST URI

XMLHttpRequest cannot load http://hfdvcbapp01.vm.itg.corp.us.shldcorp.com:8180/cnb/cnb/report/summary?Company=IT. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:64033' is therefore not allowed access.
I am getting this error when i am trying to load data from json which situated at the server.How can i resolve this.
Access-Control-Allow-Origin header should be set in the response,
if it is not from the same origin of the URL it was sent from, the header should be set from the respone - meaning - the server responding to the request in youre case - http://hfdvcbapp01.vm.itg.corp.us.shldcorp.com:8180,
if the server is under youre control just handle it, if its an outside service you should request this.
Your api is not returning header
Access-Control-Allow-Origin: http://yourdomain.com
to allow specific domain
or
Access-Control-Allow-Origin: *
to allow all
PS. Also make sure that headers are actually there. Pay attention that CORS actually send 2 requests 1 will be OPTIONS, second will be actual request so if you return headers only on GET or POST it wont work. To check it in chrome presss f12, go to network and do you requests make sure that header is there
Read more

Angularjs - No 'Access-Control-Allow-Origin' header is present on the requested resource

trying to access an api with angularjs:
eg.
footballdataAPI.getTeams = function() {
$http.defaults.headers.common['Auth-Token'] = '613a6b6937394ae8a94d69f358f76902';
return $http.get('http://www.football-data.org/alpha/soccerseasons/398/leagueTable?callback=JSON_CALLBACK');
};
But I get the console error:
XMLHttpRequest cannot load http://www.football-data.org/alpha/soccerseasons/398/leagueTable?callback=JSON_CALLBACK. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://alexanderlloyd.info' is therefore not allowed access.
Do they need to allow requests from my domain on their side? Or is there something I can add to make this work ad they have already given me an authorisation token as shown in the code.
Thanks!
The server must send the Access-Controll-Allow-Origin header, telling the browser that requests from your application's host are allowed - otherwise the browser refuses to make such request (as a built-in security measure).
If interested, you can read a much more detailed explanation here.

Restangular api calls to external getting 'No Access Allowed'

Following Restangular's documentation and includes an example of this:
// GET to http://www.google.com/ You set the URL in this case
Restangular.allUrl('googlers', 'http://www.google.com/').getList();
I am trying to do the same for angel.co
$scope.trial = Restangular.allUrl('googlers', 'https://api.angel.co/1/users/267770').getList();
And keep getting error
XMLHttpRequest cannot load https://api.angel.co/1/users/267770. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8000' is therefore not allowed access.
Any solutions?
The server (api.angel.co) is not responding with Access-Control headers which results in this error.
When sending XHR requests to domains different from the origin domain web browsers are checking if the service allows this. In your case api.angel.co would need to include the header Access-Control-Allow-Origin: * as part of the response (which it does not).
Assuming you cannot change api.angel.co, an alternative would be to build a server-side proxy (e.g. in node.js) which allows Cross-Origin Resource Sharing.
Check out this great article about Cross-Origin Resource Sharing (CORS).

Resources