ajax - Prevent double click on submit

前端 未结 2 595
不知归路
不知归路 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: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.

提交回复
热议问题