2016-08-14 4 views
0

Friends、私はdjangoでajax jsonの応答を取得しようとしています。jsonの構文解析では、django jqueryのオブジェクトが1つだけ返されます。

コンソールログにはすべてのjsonオブジェクトが表示されますが、jsonを解析してhtmlの除算にフィールドを追加している間は、同じことは成り立ちません。 1つのオブジェクトのフィールドだけが表示されます。私は私が間違っているつもりだところを見つけ出すことはできません

$("#all_questions").on("click", 
    function(event){ 
     all_questions(); 
    } 
); 

function all_questions() 
{ 
    console.log("all_questions() working.."); 


    $.ajax({ 
     url : "/questions", 
     type : "GET", // http method 
     data : { }, 

     success : function(json) { 
     console.log(json); // log the returned json to the console 
     $("#content").empty(); 
     data = JSON.parse(json); 
     $.each(data, function(idx, obj) { 
      $('#content').html(obj.fields.title); 
     }); 
    } 
    , 


    error : function(xhr,errmsg,err) { 

     console.log(xhr.status + ": " + xhr.responseText); 
    } 
    }); 
} 

を次のように

私のjavascriptのです。

答えて

1

問題は、この行にある:

$('#content').html(obj.fields.title);

あなたがHTMLを更新するたびに、あなたはそれだけに一つの値を渡します。 htmlファイルでコンテンツを追加したり、複数のインスタンスを作成したり(リストの名前など)

+0

patitoに感謝します。 – amankarn

関連する問題