【发布时间】:2014-05-29 22:01:10
【问题描述】:
我正在尝试返回一个 json 对象以呈现到我的模板中的网格。 我就是这样做的。
views.py
def ajax_up(request):
history_data=Upload_history.objects.all()
history=serializers.serialize("json",history_data)
return HttpResponse( history, mimetype='application/json' )
html
$(".reply").click(function(){
$.ajax({
url: "/ajax_up/",
type: 'GET', //this is the default though, you don't actually need to always mention it
dataType: "json",
success: function(data) {
alert("awasome"+ data)
},
failure: function(data) {
alert('Got an error');
}
});
所以我声明一个对象来保存数据
var data = {{history|safe}};
如上图所示,从 ajax 调用返回历史记录 但是当我做警报(数据)时,我得到[对象对象],[对象对象]..... 有人可以帮忙吗?
【问题讨论】:
-
{{history|safe}}的引用是什么?那是一个django模板标签,但是这里没有模板视图。