문제

The following call was working for me in AngularJS:

var baseUrl = 'http://aaa.com/';
return $http.jsonp(baseUrl + 'root/' + path + '?action=doit&callback=JSON_CALLBACK';

Now, I've decided to try to use Restangular and have replaced that with the following:

return Restangular.all('root/' + path).getList({action: 'doit', callback: 'JSON_CALLBACK'} );

But I get the error:

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

What am I doing wrong?

I'm initializing Restangular as follows:

.config(function(RestangularProvider) {
 RestangularProvider.setBaseUrl('http://aaa.com/');
 RestangularProvider.setDefaultRequestParams('jsonp', {callback: 'JSON_CALLBACK'});
});

올바른 솔루션이 없습니다

다른 팁

To enable CORS, you have to make the following change. Don't forget that the server side needs to support CORS as well.

Inject httpProvider in your app.js and do the following.

$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top