0
朋友,我試圖在django中獲取ajax json響應。解析json在django中只返回一個對象jquery
雖然控制檯日誌顯示了每個json對象,但在解析json並向html中的分區添加字段時,情況並非如此。只有一個對象的字段出現。
我的JavaScript如下
$("#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);
}
});
}
我想不通我要去哪裏錯了。
感謝patito,它幫助! – amankarn