2013-03-06 3 views
0

Google API에서 데이터를 표시하려고하지만 계속 결과가 "정의되지 않음"으로 표시됩니다. 여기 내 코드는 다음과 같습니다Google API Json Ajax/Jquery Call

$(document).ready(function() { 
var url='https://www.googleapis.com/books/v1/volumes?q=harry+potter&maxResults=9' 
$('#button').click(function() { 
    $.getJSON(url,function(data){ 
     $('#content').empty(); 
     $.each(data.items, function(entryIndex, entry){ 
      var html = '<div class="result">';      
      html += '<h3>' + entry.id + '</h3>'; 
      html += '<div class="title">' + entry.volumeInfo.title + '</div>';     
      html += '<div class="author">' + entry.volumeInfo.authors + '</div>';           
      $('#content').append(html); 
     });       
    }); 
    return false; 
    }); 
}); 

문제는 루프 만 한 행을 계산 한 것이 었습니다 :로 보일 것입니다

$(document).ready(function() { 
var url='https://www.googleapis.com/books/v1/volumes?q=harry+potter&maxResults=9' 
    $('#button').click(function() { 
     $.getJSON(url,function(data){ 
      $('#content').empty(); 
      $.each(data, function(entryIndex, entry){ 
       var html = '<div class="result">';      
       html += '<h3>' + entry['id'] + '</h3>'; 
       html += '<div class="title">' + entry['title'] + '</div>';     
       html += '<div class="author">' + entry['author'] + '</div>';           
       $('#content').append(html); 
      });       
     }); 
     return false; 
    }); 
}); 

답변

2

코드는 사용자가 API에 대한 원하는 정보를 얻기 위해 다음과 같습니다. 목록에있는 항목 수를 계산하려면 가져와야했습니다. 이는 정확한 수를 얻을 수 있도록 'data.items'를 넣음으로써 처리됩니다. 나는 이것을 더 일찍 붙 잡지 않았다. 미안하다. 이 방법으로 문제가 해결되면 알려주십시오.

+0

도움 주셔서 감사합니다. 하지만 여전히 작동하지 않는 것 같습니다 : http://pixeloft.com/clients/popdust/ – user2140126

+0

사이트의 Javascript 콘솔에서 샘플을 직접 수행 한 후 문제에 대한 해결책을 제공하기 위해 답을 편집했습니다. –

+0

이 작품! 정말 고맙습니다! – user2140126