Ajax 调用提交处理程序 Jquery 验证

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42745511/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 17:19:09  来源:igfitidea点击:

Ajax Call on submit handler Jquery Validation

jqueryajaxjquery-validate

提问by Hashaam

I have a form which have multiple select dropdown name=select[], and this form is validate from Jquery Validation and after successful validation Submit handler call Ajax i want to send all form keys and values also include in array form , Here is My Code .

我有一个有多个选择下拉列表的 name=select[]表单,这个表单是从 Jquery 验证中验证的,成功验证后提交处理程序调用 Ajax 我想发送所有表单键和值也包括在数组表单中,这是我的代码。

function:submitHandler
{
$.ajax({
url: "processo.php", 
type: "POST",             
data: new FormData(this),
cache: false,             
processData:false,      
success: function(data)   
{
$('#loading').hide();
$("#message").html(data);
}
});
}

Now the when validation successfully done new FormData(this) not recognize form id.but when i put new Formdata($("#frmRegister")[0])then its send variables to php but not array. How can i define form id in like new Formdata("#frmRegister").Remember please i also have mulitple select array in form .

现在验证成功完成时 new FormData(this) 无法识别表单 id.but 当我把new Formdata($("#frmRegister")[0])它的发送变量发送到 php 而不是数组时。我如何定义表单 id 。 new Formdata("#frmRegister")请记住,我在表单中也有多个选择数组。

回答by Sparky

The submithandlergoes inside of the .validate()method and you would use the formargument provided by the developer.

submithandler在内部云.validate()的方法,你会使用form由开发商提供的参数。

$('#myform').validate({
    submitHandler: function(form) {
        $.ajax({
            url: "processo.php", 
            type: "POST",             
            data: new FormData($(form)),
            cache: false,             
            processData: false,      
            success: function(data) {
                $('#loading').hide();
                $("#message").html(data);
            }
        });
        return false;
    },
    // other options
});

You could also use $(form).serialize();instead.

您也可以$(form).serialize();改用.

回答by Hashaam

Thank You Very Much For giving Answer i have solution here is code .

非常感谢您给出答案,我在这里有解决方案是代码。

function:submitHandler
{
$("#frmRegister").load("submit",function(e)// Trigger Submit When Validation Done
{
$.ajax({
url: "processo.php", 
type: "POST",             
data: new FormData(this),
cache: false,             
processData:false,      
success: function(data)   
{
$('#loading').hide();
$("#message").html(data);
}
});
});
}