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

16,438

Solution 1

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

Solution 2

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";
    }});
Share:
16,438

Related videos on Youtube

Anton Dimitrov
Author by

Anton Dimitrov

x-MuZiC.cOm | FREE DOWNLOAD MP3 VIDEO TXT CD

Updated on September 15, 2022

Comments

  • Anton Dimitrov
    Anton Dimitrov over 1 year

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

    • putvande
      putvande over 10 years
      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?
    • adeneo
      adeneo over 10 years
      Using ajax to redirect is the exact opposite of it's intended use.