Prevent double submission of forms in jQuery

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

    Change submit button:

    
    

    With normal button:

    
    

    Then use click function:

    $("#submitButtonId").click(function () {
            $('#submitButtonId').prop('disabled', true);
            $('#myForm').submit();
        });
    

    And remember re-enable button when is necesary:

    $('#submitButtonId').prop('disabled', false);
    

提交回复
热议问题