2011-11-08 3 views
0

FB API를 사용하여 의견을 얻으려고합니다. 내가 얻은 json은 정확하지만 json을 통해 반복하는 데 문제가 있습니다. 여기 JSON을 통한 페이스 북의 의견,

내 JS입니다 : -

$(document).ready(function() { 
    $('.showcomments a').click(function() { 

     var id = $(this).attr('id').split('-'); 
     id = id[1]; 

     $.ajax({ 
      url: "https://graph.facebook.com/"+id+"/comments?access_token=foobar", 
      type: 'GET', 
      datatype: 'json', 
      success: function(comments) { 

       $.each(comments.data, function(i, comment){ 
        alert('<h3>'+comment.from.name+'</h3><p>'+comment.message+'</p>'); 
       }); 

      } 
     }); 

    }); 
}); 

나는 문제가 comments.data

불을 지르고과 생각은 다음과 제공 : - 어떤 도움

a is undefined 
[Break On This Error] (function(a,b){function cv(a){return f...ndexOf(".")>=0&&(i=h.split("."),h=i. 

건배를

+0

'console.log (comments)'를'success' 콜백의 시작 부분에 넣으면 어떻게 될까요? – Blazemonger

+0

{ "데이터": [{ "id": "foobar", "발신인": { "이름": "foobar", "id": "foobar"}, "메시지": "foobar", "created_time" "2011-11-08T14 : 31 : 22 + 0000"}], "paging": { "next": "https://graph.facebook.com/foobar/comments?access_token=foobar&limit=25&offset=25"}} – pjknight

+0

http://jsfiddle.net/mblase75/bFY6y/ - 여기에서 잘 작동하는 것 같습니다. – Blazemonger

답변

0

사용해보기 $ (document) .ready (function() {.$ ('. showcomments A')을 클릭 (함수() {

var id = $(this).attr('id').split('-'); 
    id = id[1]; 

    $.ajax({ 
     url: "https://graph.facebook.com/"+id+"/comments?access_token=foobar", 
     type: 'GET', 
     datatype: 'json', 
     complete: function(comments) { 

      $.each(comments.data, function(i, comment){ 
       alert('<h3>'+comment.from.name+'</h3><p>'+comment.message+'</p>'); 
      }); 

     } 
    }); 

}); }});

성공 대신 성공

+0

제안 주셔서 감사하지만 그 작동하지 않았다. – pjknight

관련 문제