ATlaS ATlaS - 1 year ago 130
Javascript Question

jQuery - load html response into whole page

In my ajax code, I get a html response. How can I replace the whole page to this html response? I only find

, which only can redirct url response.

My code:

url: '/someurl',
data: {'key': value},
type: 'POST',
success: function(html_data) {
# how to load this html_data into the whole page?
error: ...

Answer Source

jQuery replaceWith should get it done for you ;)

$( "html" ).replaceWith( data );

Where data is html received from server...

Entire code will look something like this...

$.get( "", function( data ) {
  $( "html" ).replaceWith( data );

Learn more about jQuery here...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download