Dirty Bird Design
Dirty Bird Design

Reputation: 5553

change page on success with jQuery $.ajax

This is a stupid simple question, but ive been staring at it all night and can't get it right. I need to change the page on sucess, right now I can only get it to work using .load to load a div from the desired page. I want it to redirect to the entire page.

Here is what I have

success: function(data) {
    if (data=="Error") {
    $("#error").show();
    $("#processing").hide();
    } else {
        $("#contain").load("finalPage.php #desiredDiv");
    }
}

I just want it to go to that page instead of loading a chunk of it. window.load isn't working

Upvotes: 3

Views: 14243

Answers (1)

Nick Craver
Nick Craver

Reputation: 630627

By setting window.location.href you'll cause the browser to redirect, like this:

success: function(data) {
    if (data == "Error") {
        $("#error").show();
        $("#processing").hide();
    } else {
        window.location.href = "finalPage.php";
    }
}

Upvotes: 8

Related Questions