2013-02-03 5 views
0

$ 리소스를 잘못 사용하고 있습니다 (대개는 오늘 각도로 시작한 것 같습니다). 또는 JSON이 잘못되었습니다.AngularJS가 유효한 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를 바이올린 : http://jsfiddle.net/78Cab/ 및 관련 코드 JQuery와 바이올린이 같은 URL을 치는 동작

$.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); 
}); 

..

이 JSON을 명중 http://jsonproxy.aws.af.cm/proxy/http:,,api.petfinder.com,pet.getRandom;key=260f9e3a6f6670b5d9db68b281ebe7a9;format=json;location=51503http://jsonlint.com/을 유효한 JSON으로 전달합니다

다른 사람이 비슷한 문제가 있습니까?

답변

0

나는 그것을 알아 냈다. 서비스가 유효한 JSON을 반환했지만 $ resource 호출은 JSONP를 예상하고 JSON 계획을 사용할만큼 현명하지 않았습니다. JSON 대신 콜백 (JSON)을 반환하도록 서비스를 수정해야했습니다.

관련 문제