简体   繁体   English

在jQuery验证成功后,使用ajax提交表单

[英]Submitting a form with ajax after jQuery validation is successfull

Ok so I have a form that I am validating with jQuery Validation and I am trying to now submit it with AJAX. 好的,我有一个表单,我正在验证jQuery验证,我现在尝试使用AJAX提交它。 With the code below, once the form is valid and you click on submit the page reloads and the inputs are placed in the url address bar (ie method="get") 使用下面的代码,一旦表单有效并且您单击提交页面重新加载并且输入被放置在URL地址栏中(即method =“get”)

In the ajax method I have that set to POST but it doesn't appear to be using the ajax call. 在ajax方法中,我将其设置为POST但它似乎没有使用ajax调用。

What did I do wrong? 我做错了什么?

$().ready(function() {
    var $form = $(this);
   //validate the inquiry form on keyup and submit
    $("#inquiryForm").validate({
        showErrors: function(errorMap, errorList) {
            for (var error in errorMap)  {
                $.growl.error({ message: errorMap[error] });
             }
        },
        onkeyup: false,
        rules: {
            fullName: {
                required: true
            },
            email: {
                required: true,
                email: true
            },
            inquiry: {
                required: true,
                minlength: 5,
                maxlength: 500
            }
        },
        messages: {
            fullName: "Your name is required",
            email: "A valid email address is required",
            inquiry: "Your inquiry is required and must have between 5-500 characters"
        },

        submitHandler: function(form) {
            $.ajax({
                url: form_submit/inquiry_form/inquiry_form.php,
                type: "POST",
                data: $(form).serialize(),
                success: function(response) {
                    $('#inquiryFormHolder').html("Your form was submitted!");
                }            
            });
            return false;
        }
    });
});

Try to use : 尝试使用:

submitHandler: function(form) {
    $.ajax({
        url: form_submit/inquiry_form/inquiry_form.php,
        type: "POST",
        data: $(form).serialize(),
        success: function(response) {
            $('#inquiryFormHolder').html("Your form was submitted!");
        }            
    });
    $form.submit();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM