How to submit form only once after multiple clicking on submit?

后端 未结 9 2208
北荒
北荒 2020-12-13 10:41

I am having problem that when i am trying to submit the form by clicking on the submit button it takes some time to post request during this if i am again click on the Submi

9条回答
  •  时光取名叫无心
    2020-12-13 11:03

    You can add the next script to your 'layout page' (to be rendered on all the pages globally).

    
    

    Then, each time a form is submited, the submit buttons are disabled. (The submit button(s) are re-enabled when loading the page.)

    If you are using a validation framework (like jQuery Validation), it is probably that you need to re-enable the submit button(s) when a validation fails also. (because the form validation failure makes that the submit be canceled).

    If you are using jQuery Validation, you can detect the form invalidation (form submition cancellation) adding this:

    $('form').bind('invalid-form.validate', function () {
        $(':submit').removeAttr('disabled'); //re-enable on form invalidation
    });
    

    Then if a form validation fails, the submit button(s) is/are enabled again.

提交回复
热议问题