AngularJS で次の 2 つのサービスを定義しました。クロスドメイン リクエストを行っているため、どちらも 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'} }
}
);
});
サービス 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'} }
}
);
});
私のコントローラーでは、結果をスコープにバインドしています。
$scope.foo = A.get();
$scope.bar = B.get();
私の console.log() の出力によると、B は予想される結果を JSON 形式で返しますが、A は次のようなものを返します。
SyntaxError: invalid label
{"DEMO_ERFOLGX":{"offers":[{"checkin":"2012-12-01","checkout"
何か不足していますか?A から適切な JSON を受け取るにはどうすればよいですか?