Prevent double submission of forms in jQuery

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

    I can't believe the good old fashioned css trick of pointer-events: none hasn't been mentioned yet. I had the same issue by adding a disabled attribute but this doesn't post back. Try the below and replace #SubmitButton with the ID of your submit button.

    $(document).on('click', '#SubmitButton', function () {
        $(this).css('pointer-events', 'none');
    })
    

提交回复
热议问题