Search code examples
javascriptjqueryajaxparametersget

Reload entire page with AJAX request and changed GET parameters


I'm trying to reload an entire page with a jQuery AJAX request (supplying a simple GET parameter to the load), roughly in this fashion.

$.ajax({
    url: "site.php?param="+new_param,
    cache: false,
    success: function(content) {
        $("html").html(content);
    }
});

As you can see, this will cascade the <html> blocks and somehow the styling gets broken (background is suddenly white and so on).

Tricks like $(document).html(content); won't work either.

Unfortunately I haven't found any solution to this problem, yet.


Solution

  • If you are not reloading head content (loading new javascript or css), and I see no reason why you should do such a thing, you should really try to contain your content loading to content itself, ie. <body>.

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

    Edit

    In order to achieve, what I think you are trying to, you could check out https://github.com/defunkt/jquery-pjax