我想通過和Ajax調用返回的HTML呈現的HTML和我有下面的代碼片段在我看來返回通過Ajax
if request.is_ajax():
t = loader.get_template('frontend/scroll.html')
html = t.render(RequestContext({'dishes': dishes})
return HttpResponse(json.dumps({'html': html}))
和我的Ajax
$.ajax({
type: "POST",
url: "/filter_home",
data: {'name': 'me', 'csrfmiddlewaretoken': '{{csrf_token}}'},
success : function(data) {
$('.row.replace').html(data);
}
});
,並拋出以下錯誤
Exception Value: 'dict' object has no attribute 'META'
Exception Location: /opt/bitnami/apps/django/lib/python2.7/sitepackages/django/core/context_processors.py in debug, line 39
我做錯了什麼?
我已經得到一個錯誤,一切都沒有露面通過AJAX頁面上,我用jquery警報打印錯誤,我看到下面的消息「SyntaxError:Unexpected token <」。 ajax不能識別html開始標記嗎? –
NVM我發現了錯誤 –
如果AJAX調用返回HTML,訣竅是使用'$('#result').html(data)'而不是'$('#result').text(data)'(注意**'.html' **而不是'.text')。 – Jabba