Kevin Kevin - 1 month ago 5
Ajax Question

Get body markup of an AJAX response

I have an Ajax call:

callAjaxController: function(){
var url = Routing.generate('ajax_price');

type: "GET",
url: url,
cache: false,

success: function (data, status) {
// get the <body> markup to replace my actual body page

In my Ajax response, I would like to get the markup to replace my actual body page.

Is it possible? How can I do that?


Assuming your request retrieves the content of the body tag you want to use you can set the html() of the current body() element with the new content, like this:

success: function (data, status) {

Alternatively, if the response includes the <body> tag and all content within it, use replaceWith():

success: function (data, status) {

Also note that because you have destroyed all existing elements in the DOM you will need to use delegated event handlers, should you have any existing events that are handled in code.