【发布时间】:2013-02-03 04:51:09
【问题描述】:
要么我错误地使用了 $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 传递
其他人有类似的问题吗?
【问题讨论】: