2

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

4
  • 1
    What have you tried? And why do you want to do this? Why not just use a link to send the user to another page? Or are you already using AJAX to do something and want to send the user after the callback? Commented Aug 3, 2013 at 11:59
  • 2
    Using ajax to redirect is the exact opposite of it's intended use. Commented Aug 3, 2013 at 12:03
  • On success call of ajax set "window.location.reload=data.url" where url is the string you have returned from the called method Commented Aug 3, 2013 at 12:28
  • duplicate of stackoverflow.com/questions/503093/… Commented May 1, 2015 at 14:57

3 Answers 3

3

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";
    }});
Sign up to request clarification or add additional context in comments.

Comments

3
    $.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"! ;)

Comments

0

// Through an HTTP redirect

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

// Through by clicking on a link

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.