Simple views question for django / jQuery calls

I'm trying to figure out how to pass html back to a jQuery call, but for some reason my code refuses to work.

t = get_template('success.html')
html = t.render(Context({'success': True}))    # should render '<p><h1>aoeu</h1></p>'
x = "{'success' : '" + html + "'}"
return HttpResponse(x)

      

JQuery code:

$.post("adduser", data, function(responseData){
    $('#content').html(responseData.success);
}, "json");

      

if I replace the html with a literal string (just "asdf" or whatever) the #content changes correctly. If I use the rendered html it doesn't show. What am I doing wrong? Also, is this the correct way to make a dynamic call using django?

+1


a source to share


1 answer


You are using the "json" datatype, you need to use "html". ( source )



$.post("adduser", data, function(responseData){
    $('#content').html(responseData.success);
}, "html");

      

+2


a source







All Articles