0

要么我错误地使用了 $resource(很可能,今天刚从 angular 开始),要么我的 JSON 不好。

AngularJS 小提琴: http: //jsfiddle.net/8zVxH/1/和相关代码:

angular.module('app', ['ngResource']);

function AppCtrl($scope, $resource) {
var url = 'http:,,api.petfinder.com,pet.getRandom;key=260f9e3a6f6670b5d9db68b281ebe7a9;format=json;location=51503';
$scope.petfinder = $resource('http://jsonproxy.aws.af.cm/proxy/:action', 
                                 {action:url, callback:'JSON_CALLBACK'},
                                 {get: {method:'JSONP'}});

$scope.indexResult = $scope.petfinder.get();

}

jQuery Fiddle: http: //jsfiddle.net/78Cab/和相关代码

$.ajax({
  url: 'http://jsonproxy.aws.af.cm/proxy/http:,,api.petfinder.com,pet.getRandom;key=260f9e3a6f6670b5d9db68b281ebe7a9;format=json;location=51503',
  method: 'GET'
}).done(function (data) {
  console.log(data);
});

jQuery fiddle 可以访问相同的 URL ..

点击这个 JSON URL http://jsonproxy.aws.af.cm/proxy/http:,,api.petfinder.com,pet.getRandom;key=260f9e3a6f6670b5d9db68b281ebe7a9;format=json;location=51503通过http://jsonlint .com/作为有效的 JSON

还有其他人有类似的问题吗?

4

1 回答 1

0

我想到了。即使服务返回了有效的 JSON,$resource 调用也期待 JSONP,并且不够聪明,无法使用计划 JSON。我不得不修改服务以返回回调(JSON)而不仅仅是 JSON。

于 2013-02-03T15:21:36.290 回答