我正在尝试从django HttpResponse获取json对象。实际上访问'form_validation'值。但我不能。有什么建议吗?
这是我的HttpResponse
return HttpResponse(simplejson.dumps({'response_data':response_data, 'form_validation':form_validation, 'guest': guest, 'error_list':error_array}), mimetype="application/json")
答案 0 :(得分:0)
您需要为具有json响应对象的ajax调用定义success
函数:
$.ajax({
type: 'POST',
url: url,
data: {'csrfmiddlewaretoken': '{{csrf_token}}'},
dataType: "text",
success: function(response) {
var response_data = response.response_data;
var form_validation = response.form_validation;
// access other fields
},
error: function(rs, e) {
alert(rs.responseText);
}
});