我在AngularJS中定义了以下两个服务.两者都应该返回JSONP,因为我正在做跨域请求.
服务A:
angular.module('ServiceA', ['ngResource']).
factory('A', function ($resource) {
return $resource('url/offers', {},
{
get: { method: 'JSONP', params: {property_code: 'DEMO_ERFOLGX', adults: '2',
callback: 'JSON_CALLBACK'} }
}
);
});
Run Code Online (Sandbox Code Playgroud)
服务B:
angular.module('ServiceB', ['ngResource']).
factory('B', function ($resource) {
return $resource('url/search.json', {},
{
get: { method: 'JSONP', params: {property_code: 'DEMO_ERFOLGX', adults: '2',
callback: 'JSON_CALLBACK'} }
}
);
});
Run Code Online (Sandbox Code Playgroud)
在我的Controller中,我将结果绑定到我的范围:
$scope.foo = A.get();
$scope.bar = B.get();
Run Code Online (Sandbox Code Playgroud)
根据我的console.log()输出,B以JSON格式返回预期结果,而A返回如下内容:
SyntaxError: invalid label
{"DEMO_ERFOLGX":{"offers":[{"checkin":"2012-12-01","checkout"
Run Code Online (Sandbox Code Playgroud)
我错过了什么吗?为了从A接收适当的JSON,我该怎么办?