Adir
Adir

Reputation: 1423

Is it possible to use JQuery.Load() to replace the entire document?

    $(document).load("somepage.aspx", function (responseText, textStatus, xhr) {

});

This is not working.
Is there any way to use the load function to replace the entire document including the head?

EDIT: I don't want to refresh my page, I have to use AJAX.

Upvotes: 5

Views: 3601

Answers (5)

Esailija
Esailija

Reputation: 140230

$.get("somepage.aspx", function (data) {
    document.open();
    document.write(data);
    document.close();
    $.cache = {};
}, "text");

Upvotes: 7

Arif
Arif

Reputation: 1726

You should redirect you page when page is completely loaded.

    $(window).load(function(){
       document.href.location = "your_page";
    });

Upvotes: 0

dotty
dotty

Reputation: 41433

$(function(){
    $.get('my_page.html', function(e){
        $(document).empty().append(e);
    });
});

Try that. my_page.html gets loaded, then jQuery finds the document object, removes everything and appends it with the my_page.html content.

Upvotes: 0

Alexander
Alexander

Reputation: 1297

You can add iframe and load new page into it.

Upvotes: 0

secretformula
secretformula

Reputation: 6432

You could use a Jquery Ajax query to grab some html from the server the remove everything from the document and replace it with the content.

Upvotes: 0

Related Questions