2011-11-08 12 views
0

FB APIを使用してコメントを取得しようとしています。私が返すjsonは正しいですが、私はjsonを通してループするのに問題があります。ここでFacebookのコメント、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(コメント)'を 'success'コールバックの開始時に表示するとどうなりますか? 「foobar」、「foobar」、「created_time」: – Blazemonger

+0

{"データ": "{" "2011-11-08T14:31:22 + 0000"}]、 "ページング":{"次": "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

関連する問題