Prevent double submission of forms in jQuery

后端 未结 22 1585
旧时难觅i
旧时难觅i 2020-11-22 08:10

I have a form that takes a little while for the server to process. I need to ensure that the user waits and does not attempt to resubmit the form by clicking the button agai

22条回答
  •  [愿得一人]
    2020-11-22 08:36

    Please, check out jquery-safeform plugin.

    Usage example:

    $('.safeform').safeform({
        timeout: 5000,  // disable next submission for 5 sec
        submit: function() {
            // You can put validation and ajax stuff here...
    
            // When done no need to wait for timeout, re-enable the form ASAP
            $(this).safeform('complete');
            return false;
        }
    });
    

提交回复
热议问题