Search code examples
jqueryfunctionhttp-redirectdelay

Delay jquery redirect


I've seen some functions with normal javascript here on stackoverflow, regarding my question. Although I haven't seen anything that will delay the redirect function which I have here.

    if(data=='success'){
        $('form').fadeOut();
        $('#status').addClass('noti-success').html('Please wait while we redirect you...').slideDown();
        redirect("?i=a");
    }

As you can see, it will redirect immediately to ?i=a, and therefore makes the notifiction message only show for a second or so.

How can I delay the redirect function with X number of seconds?


Solution

  • You can make the redirect after the message was hidden:

    $('#status')
      .addClass('noti-success')
      .html('Please wait while we redirect you...')
      .delay(2000)
      .slideDown(function() {
          redirect("?i=a");
      });