Jquery prevent multiple submit

后端 未结 7 874
花落未央
花落未央 2020-12-30 09:58

I want to prevent multiple submit if someone click on one of the submit buttons multiple times.

How can unbind or undelgate in this case th

7条回答
  •  情书的邮戳
    2020-12-30 10:39

    If you have users who insist on having an active submit button all the time you can use a variable to track the progress. Something like this:

    saving_record = 0; //set variable to show if form is in submission
    $(document).ready(function () {
        $('#form').on('submit', function (e) {
            if (saving_record === 0) { //If not submitted yet, submit form
                saving_record = 1; //Set variable to show form is in submission
                $.ajax({
                    success: function (data) {
                        saving_record = 0; //Reset variable to allow record update
                    },
                    error: function (data) {
                        saving_record = 0; //Reset variable to allow record update in case of error
                    }
                })
            }
        });
    });
    

提交回复
热议问题