【发布时间】:2014-05-16 01:37:37
【问题描述】:
以下调用在 AngularJS 中为我工作:
var baseUrl = 'http://aaa.com/';
return $http.jsonp(baseUrl + 'root/' + path + '?action=doit&callback=JSON_CALLBACK';
现在,我决定尝试使用 Restangular 并将其替换为以下内容:
return Restangular.all('root/' + path).getList({action: 'doit', callback: 'JSON_CALLBACK'} );
但我得到了错误:
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:9000' is therefore not allowed access.
我做错了什么?
我正在按如下方式初始化 Restangular:
.config(function(RestangularProvider) {
RestangularProvider.setBaseUrl('http://aaa.com/');
RestangularProvider.setDefaultRequestParams('jsonp', {callback: 'JSON_CALLBACK'});
});
【问题讨论】:
-
好吧,您的呼叫不是作为 jsonp 请求发送的,但我不知道为什么。我会启动您的调试器并确保调用以您期望的方式发生并且您的参数得到尊重。
标签: angularjs restangular