ajax - Prevent double click on submit

前端 未结 2 586
不知归路
不知归路 2020-12-20 14:51

How can I prevent the user from double clicking submit button on my signup form which is an ajax partial view?

I regret to ask since this would have

相关标签:
2条回答
  • 2020-12-20 15:30

    UPDATE: submission was not working because onclick was not returning true

    <input type="submit" value="Sign Up" onclick="this.disabled = true; return true;"/>

    this will disable the button and the second click on the button won't work

    0 讨论(0)
  • 2020-12-20 15:34

    Try with the following script:

    $('form').submit(function () {
        if ($(this).valid()) {
            $(':submit', this).attr('disabled', 'disabled');
        }
    });
    

    Make sure you execute it also in the success callback of your AJAX request in order to reattach the submit event when the form is replaced with a new content in the DOM, or the second time it might no longer work.

    0 讨论(0)
提交回复
热议问题