Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.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
Jquery 表单保存数据并在出错后重新提交_Jquery_Html_Forms - Fatal编程技术网

Jquery 表单保存数据并在出错后重新提交

Jquery 表单保存数据并在出错后重新提交,jquery,html,forms,Jquery,Html,Forms,我的问题是表单保存了出错后提交的数据,如果我多次单击submit按钮,那么表单会发送同样多的数据 下面是处理表单的JS。我必须指出,它实际上并不做“提交”。我的问题在于成功回调中的“else” $('#reg_form').on('submit', function(e){ e.preventDefault(); $('#error_box').hide(); $('#error_box').html("") var $mail = $('#reg_email'

我的问题是表单保存了出错后提交的数据,如果我多次单击submit按钮,那么表单会发送同样多的数据

下面是处理表单的JS。我必须指出,它实际上并不做“提交”。我的问题在于成功回调中的“else”

 $('#reg_form').on('submit', function(e){
    e.preventDefault();
    $('#error_box').hide();
    $('#error_box').html("")
    var $mail = $('#reg_email').val();
    var $usn = $('#reg_username').val();
    var $pwd = $('#reg_password').val();

data = $(this).serializeArray();

$.ajax({
    url: 'PHP/validate.php',
    type: 'post',
    data: data,
    dataType : 'json',
    success: function (dat) {
        if(dat.error==0){
            alert('user added');
        }else{
            var length = dat.error_codes.length;
            for (var i = 0; i < length; i++) {
                $('#error_box').html( $('#error_box').html() + dat.error_codes[i] + '<br/>' );
            }
            $('#error_box').show(500);
            setTimeout(function(){
                $('#error_box').hide(1500, function(){$('#error_box').html("");});  
            }, 1500);
        }
    },
    error: function(){
        alert('failure');
    }
   });
 });
$('reg_form')。关于('submit',函数(e){
e、 预防默认值();
$(“#错误框”).hide();
$('#错误框').html(“”)
var$mail=$('#reg_email').val();
var$usn=$('#reg_username').val();
var$pwd=$('#reg_password').val();
data=$(this.serializeArray();
$.ajax({
url:'PHP/validate.PHP',
键入:“post”,
数据:数据,
数据类型:“json”,
成功:功能(dat){
如果(数据错误==0){
警报(“用户添加”);
}否则{
变量长度=dat.error_codes.length;
对于(变量i=0;i');
}
$('错误框')。显示(500);
setTimeout(函数(){
$('#error_box').hide(1500,function(){$('#error_box').html(“”;});
}, 1500);
}
},
错误:函数(){
警报(“故障”);
}
});
});
如何清除表单中保存的数据