Search code examples
javascriptjqueryformsdelay

How to trigger a delayed jQuery event?


I'm writing a workaround for web form. The given problem is that hitting Submit pops out a loading animation. The content is saved, but the form is still shown, as is the loading animation.

The idea is to trigger an event, 2-3 seconds after the Submit click, that will reset the form content and hide the loading animation.

How would you suggest to approach this?

Thank you.


Solution

  • jQuery Form came to the rescue.

    $('form#id').ajaxForm(function() {
        // do stuff
    });
    

    This will run the callback after the form is submitted.