Question

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'});
});

Pas de solution correcte

Autres conseils

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'];
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top