Jquery AngularJS未解析有效的JSON
要么我没有正确使用$resource(很可能是从angular开始的),要么我的JSON不好 AngularJS fiddle:和相关代码:Jquery AngularJS未解析有效的JSON,jquery,json,angularjs,Jquery,Json,Angularjs,要么我没有正确使用$resource(很可能是从angular开始的),要么我的JSON不好 AngularJS fiddle:和相关代码: angular.module('app', ['ngResource']); function AppCtrl($scope, $resource) { var url = 'http:,,api.petfinder.com,pet.getRandom;key=260f9e3a6f6670b5d9db68b281ebe7a9;format=json;lo
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:及其相关代码
$.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传递的JSON URL
还有人有类似的问题吗?我想出来了。即使服务返回有效的JSON,$resource调用也需要JSONP,并且不够聪明,无法使用plan JSON。我不得不修改服务以返回回调(JSON),而不仅仅是JSON