Prevent double submission of forms in jQuery

后端 未结 22 1333
旧时难觅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:38

    Use simple counter on submit.

        var submitCounter = 0;
        function monitor() {
            submitCounter++;
            if (submitCounter < 2) {
                console.log('Submitted. Attempt: ' + submitCounter);
                return true;
            }
            console.log('Not Submitted. Attempt: ' + submitCounter);
            return false;
        }
    

    And call monitor() function on submit the form.

        
    ....

提交回复
热议问题