sto cercando di tornare html tramite e Ajax chiamata e ho il seguente frammento di codice a mio avvisoTornando rendering Html tramite Ajax
if request.is_ajax():
t = loader.get_template('frontend/scroll.html')
html = t.render(RequestContext({'dishes': dishes})
return HttpResponse(json.dumps({'html': html}))
e il mio Ajax
$.ajax({
type: "POST",
url: "/filter_home",
data: {'name': 'me', 'csrfmiddlewaretoken': '{{csrf_token}}'},
success : function(data) {
$('.row.replace').html(data);
}
});
e getta la seguente errore
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
cosa sto facendo di sbagliato?
Sono stato sempre un errore, nulla è mostrato sulla pagina tramite la tecnologia AJAX, ho stampato l'errore con un avviso jQuery e vedo il seguente messaggio "SyntaxError: Unexpected token <". Ajax non riconosce il tag di apertura html? –
NVM ho rilevato l'errore –
Se la chiamata AJAX restituisce HTML, il trucco è usare '$ ('# result'). Html (data)' invece di '$ ('# result'). Testo (dati)' (avviso ** '.html' ** invece di' .text'). – Jabba