Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 防止重复提交表单_Javascript_Php_Jquery_Forms_Twitter Bootstrap - Fatal编程技术网

Javascript 防止重复提交表单

Javascript 防止重复提交表单,javascript,php,jquery,forms,twitter-bootstrap,Javascript,Php,Jquery,Forms,Twitter Bootstrap,我有一个表单的提交事件处理程序和一个bootstrapValidator对象。如果我不加注释,表单将提交两次(单击提交按钮)。有谁知道,我怎样才能防止双重屈服 引导验证程序: $('#ins3').bootstrapValidator({ container: '#messages3', feedbackIcons: { valid: 'glyphicon glyphicon-ok', invalid: 'glyphicon glyphicon-r

我有一个表单的提交事件处理程序和一个bootstrapValidator对象。如果我不加注释,表单将提交两次(单击提交按钮)。有谁知道,我怎样才能防止双重屈服

引导验证程序:

$('#ins3').bootstrapValidator({
    container: '#messages3',
    feedbackIcons: {
        valid: 'glyphicon glyphicon-ok',
        invalid: 'glyphicon glyphicon-remove',
        validating: 'glyphicon glyphicon-refresh'
    },
    fields: {
        manufacturername: {
            validators: {
                notEmpty: {
                    message: 'Please enter a new brandname'
                }

            }
        }
    }
});
提交表单的事件处理程序:

// Product
$("#ins3").submit(function(event) {
    //alert('test');
    var ajaxRequest;

    // Stop form from submitting normally 
    event.preventDefault();

    // Clear result div
    $("#brandResultDiv").html('');

    // Get from elements values 
    var values = $(this).serialize();

       ajaxRequest= $.ajax({
            url: "Subpages/addBrandname_script.php",
            type: "post",
            data: values
        });

      //  request cab be abort by ajaxRequest.abort() 

     ajaxRequest.done(function (response, textStatus, jqXHR){
          // POST Completed Successfully
          $("#brandResultDiv").html(response);
          $("#brandResultDiv").show().delay(2000).fadeOut();
     });

     // On failure of request this function will be called  
     ajaxRequest.fail(function (){

       // show error
       $("#brandFailDiv").html('An error occurred while submitting the request.');
     });

});

我找到了答案,它显示了bootstrapValidator对象中的提交处理程序。我想知道是否还有另一种方法,因为我有很多表单是用上述方法编写的,这意味着我必须重写其中的每一个表单。

使用带有会话/令牌的服务器端方法;故事结束。也许这个例子可以帮助你: