Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

angularjs - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...