【发布时间】:2016-08-14 18:10:02
【问题描述】:
朋友们,我正在尝试在 django 中获取 ajax json 响应。
虽然控制台日志显示每个 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);
}
});
}
我不知道我哪里出错了。
【问题讨论】: