Saturday, June 30, 2012

Re: javascript in django template not executed when request is sent via ajax

On Sat, Jun 30, 2012 at 11:54 AM, Psamathos <> wrote:
> If your web server is in fact serving the content with the incorrect
> Content-Type header (You can verify this by inspecting the response in the
> Net tab of Firebug or Chrome) jQuery can convert the response regardless of
> the content-type if you specify a two space-separated values in your
> dataType. Try dataType: "text html" in your $.ajax function.

I've been poking around with the debugger. For reference, here's the code:

var $form = $('form.roll');
url = $form.attr('action');

var $report = $('#report');

url: url,
data: $form.serialize(),
dataType: 'html',
success: function (html, textStatus) {
.html($('#report', html).html())
opacity: 1.0

The html variable passed into the success function contains the entire
page, including the javascript. I tried doing:


But the parts of the page that were not the results (i.e. #report) all
were duplicated (the page was displayed within the page). But even
there, the javascript wasn't included in the page, even though is was
in the html variable.

$('#report', html).html() contained just the html, without the
javascript. What I need is some way to get both the javascript and the
html of $('#report') and then pass that into $report.html(). Are there
javascript or jQuery methods that will allow me to do that?

Alternatively I could extract the javascript from the html variable
passed into the success function. But then how would I make that part
of $report.html()?

You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

No comments:

Post a Comment