要么我错误地使用了 $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
还有其他人有类似的问题吗?