-3

I am submiting form like

$(this).parents("form").ajaxForm(options);

how can I set timeout? mean I want to redirect page after 5 seconds of form submission

Gulzar Ali
  • 21
  • 3

1 Answers1

0

So set success and use a timeout

$("#foo").ajaxForm({
    success: function(res, status, xhr, form) {
        window.setTimeout(function(){
          window.location.href = "http://www.example.com";
        }, 5000);
    }
});
epascarello
  • 204,599
  • 20
  • 195
  • 236
  • `location.href = ...` is not a redirect. `location.replace(...)` is. – D. Pardal Jul 07 '20 at 13:42
  • 2
    It sure is. Try it in your console. – Jeremy Thille Jul 07 '20 at 13:42
  • 1
    So you want to not allow back using replace? – epascarello Jul 07 '20 at 13:43
  • 1
    If the downvote was for the somewhat semantic difference in how to redirect in JavaScript, there [is information about that too](https://stackoverflow.com/q/503093/328193). – David Jul 07 '20 at 13:44
  • It is not a redirect. It's a navigation. If you press the back button you go to the page that used `location.href`. A redirect replaces the entry in the history stack. – D. Pardal Jul 07 '20 at 13:44
  • @D.Pardal potato/potato - most people would call `location.href=` a "redirect". Very few people would call it a "navigation". "A redirect replaces the history stack" - can you back that up with evidence? Most people asking questions on here would call this a "replace", not a "redirect" (at least in javascript questions). IMO OP is clearly asking about moving to a new url (navigate in your parlance) not "replacing" the URL. – freedomn-m Jul 07 '20 at 16:21