2

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

Anton Dimitrov
  • 51
  • 1
  • 1
  • 7
  • 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? – putvande Aug 03 '13 at 11:59
  • 2
    Using ajax to redirect is the exact opposite of it's intended use. – adeneo Aug 03 '13 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 – Nitin Varpe Aug 03 '13 at 12:28
  • duplicate of http://stackoverflow.com/questions/503093/how-can-i-make-a-redirect-page-using-jquery – Patrick W. McMahon May 01 '15 at 14:57

3 Answers3

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";
    }});
Uttam K C
  • 204
  • 2
  • 4
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"! ;)

dbanet
  • 685
  • 5
  • 18
0

// Through an HTTP redirect

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

// Through by clicking on a link

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

Arun Prasath
  • 100
  • 6