首页 > 代码库 > js 防止表单异步重复提交

js 防止表单异步重复提交

<form id="formData" method="post" action="${pageContext.request.contextPath }/save">

    <input type="button" value="http://www.mamicode.com/确认提交" class="tj-btn" id="tj">

</form>

<script type="text/javascript">

    $(‘#tj‘).click(function(){

        checkSubmit();

        $.ajax({

            type: ‘POST‘,

    url: ‘${pageContext.request.contextPath }/save‘,

    data: $(‘#formData‘).serialize(),

    dataType:‘json‘,

    success: function(data){

        if(data.result==1){

            $(‘#formData‘)[0].reset();

            alert(‘提交成功‘);

                 checkSubmitFlg = false; 

}else{

    alert(data.errorMessage);

    checkSubmitFlg = false; 

}

    },

    dataType: ‘json‘

})

    });

    var checkSubmitFlg = false;   

    function checkSubmit() {     

        if (!checkSubmitFlg) { 

     checkSubmitFlg = true;     

     return true;  

        }else{

     alert("不能重复提交");

     return false;

        }

    }


</script>


js 防止表单异步重复提交