I’m replacing the body html with ajax received html.
the problem is that I have duplicated HEAD section.
I first need to remove the whole lines till from the received html and then use:
$('body').html(data);
I’m getting the html as result from POST.
This is a well formatted html.
I’m using Django’s render_to_response to send the response back.
How can I achieve such thing?
Try
$('body').html($(data).find('body'));. This will work if you have well-formed HTML.Edit: this won’t work; see Fabricio’s comment below and my reply for why. One workaround is to wrap everything inside your
bodyin a div with a given ID, then select for this ID like so:$('body').html($(data).filter('#chosenid'));Of course, this is really no different from saying$('body').load('remote_page.html #chosenid');which combines the AJAX call into the same request.