Anton Dimitrov
Anton Dimitrov

Reputation: 51

How can I make a redirect page in jQuery/JavaScript when using ajax?

How can I redirect the user from one page to another using jQuery -> Ajax? Thanks for your time.

Upvotes: 2

Views: 16457

Answers (3)

Arun Prasath
Arun Prasath

Reputation: 100

// Through an HTTP redirect

window.location.replace("http://stackoverflow.com");

// Through by clicking on a link

window.location.href = "http://stackoverflow.com";

Upvotes: 0

dbanet
dbanet

Reputation: 695

    $.ajax({
        url:"http://where.to/redirect",,
        async:false,
    });

This will load the url synchroniously, that means redirect the user "in jquery/javascript when using ajax". To "make a redirect page", write this:

    <script type="application/javascript" language="javascript">
    $.ajax({
        url:"http://where.to/redirect",,
        async:false,
    });
    </script>

... tada! We have a "a redirect page in jQuery/JavaScript when using ajax"! ;)

Upvotes: 3

Uttam K C
Uttam K C

Reputation: 204

Try this if you want to redirect to another page once ajax call is success,

    $.ajax({
    url: "page1.html",
    success:function(result){
        document.location.href="page2.html";
    }});

Upvotes: 3

Related Questions