ajax - Prevent double click on submit

浪尽此生 提交于 2019-11-29 13:34:41

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!