2012-12-19 2 views
1

나는 angelsjs http를 사용하여 itunes 검색 api에서 기본 호출을 수행하려고합니다.AngularJs and itunes

$http.jsonp("http://itunes.apple.com/search", {params:{"term":"jack+johnson"}}) 
       .success(function (data, status, headers, config) { 
        console.log("is scope : " + data); 
       }).error(function (data, status, headers, config) { 
        console.log("error" + status); 
       }); 

요청이 아니라 (상태 : 200)를 수행하고, 내가 JSON이 검색되는 것을 볼 수 있습니다, 이것은 추출물 :

{ 
"resultCount":50, 
"results": [ 
{"wrapperType":"track", "kind":"song", "artistId":909253, "collectionId":120954021,     "trackId":120954025, "artistName":"Jack Johnson", "collectionName":"Sing-a-Longs and Lullabies  for the Film Curious George", "trackName":"Upside Down", "collectionCensoredName":"Sing-a- Longs and Lullabies for the Film Curious George", "trackCensoredName":"Upside Down",  "artistViewUrl":"https://itunes.apple.com/us/artist/jack-johnson/id909253?uo=4",  "collectionViewUrl":"https://itunes.apple.com/us/album/upside-down/id120954021? i=120954025&uo=4", "trackViewUrl":"https://itunes.apple.com/us/album/upside-down/id120954021? i=120954025&uo=4", .... 

그러나 나는 JS 오류가 있습니다 "catch되지 않은 구문 에러를 : 예기치 않은 토큰 : "json 결과의 첫 번째 줄 ("resultCount ": 50).

transformResponse를 사용해 보았지만 이전에 오류가 발생했습니다.

url – {string} – Relative or absolute URL specifying the destination of the request. Should contain JSON_CALLBACK string.

다음 AngularJS와 $ http.jsonp documentation에서

app.controller('Ctrl', function($scope, $http) { 
    $http.jsonp("http://itunes.apple.com/search", { 
     params: { 
      "callback": "JSON_CALLBACK", 
      "term": "jack+johnson" 
     } 
    }).success(function(data, status, headers, config) { 
     console.log("is scope : " + data); 
    }).error(function(data, status, headers, config) { 
     console.log("error" + data); 
    }); 
});​ 

:

감사

답변

2

당신은 콜백 함수 ( JSON_CALLBACK)를 추가하는 것을 잊었다