developer747
developer747

Reputation: 15928

Jquery refresh entire page with ajax response

I am trying to solve a problem that I asked over here. To solve that problem, I am trying to do a jquery ajax, where I refresh the entire page with the response html. If I try

 success: function (msg) { 

 $(document).html(msg);
    },

it throws errors.

How do I tell jquery to replace the current page with the html contents received back in the response?

Upvotes: 2

Views: 3443

Answers (3)

Hasan Alaca
Hasan Alaca

Reputation: 232

This should work.

$("body").html(content);

If the error persists, please paste the whole code because it's not possible to find the error without seeing it.

Upvotes: 1

John Wu
John Wu

Reputation: 52240

Try this

  1. Retrieve the HTML string using AJAX
  2. Use $.parseHTML to create a disconnected DOM lattice to parse the HTML
  3. Pull items out of the $.parseHTML return value and insert them one by one into your $("head") and $("body") elements

Upvotes: 0

Jade
Jade

Reputation: 649

You need to replace just the content that's changing on the page. I doubt that your header/footer are changing too. Add an ID to whatever wrapper div you have in your layout and then change your success to this:

success: function (msg) { 
$("#ID_YOU_ADDED_GOES_IN_HERE").html(msg);
}

Upvotes: 3

Related Questions