简体   繁体   English

成功填写表单字段后如何进行Ajax调用

[英]How to make Ajax call after successfully filled the form fields

Here I am using jQuery validation. 在这里,我正在使用jQuery验证。 It is working fine, after fill all form fields I want do Ajax call but I am not able to do that. 填写所有表单字段后,我可以进行Ajax调用,但工作正常,但我无法做到这一点。 I am getting error. 我出错了。 How can I do? 我能怎么做?

jQuery(document).ready(function(){
 jQuery("#SubmitForm").validate({
        rules: {
            "address": {
                required: true                
            },
            "username": {
                required: true                
            },
            "mobileNumber": {
                required: true,
                number: true,
                minlength : 12
            },
            "userEmailid": {
                required: true,
                email: true
            },
            "message": {
                required: true
            }
        },
        messages: {
            "address": {
                required: "Please enter your Location."
            },
             "username": {
                required: "Please enter your Fullname."
            },
             "mobileNumber": {
                required: "Please enter your Mobile Number."
            },
             "userEmailid": {
                required: "Please enter your Email.",
                email: "Please enter valid Email."
            },
            "message": {
                required: "Please enter Message."
            }
        },

        /* jQuery.ajax({
             type:'POST',
             url :"php/submit_hitachiForm.php",
              data: jQuery('form#SubmitForm').serialize(),
                cache: false,
                contentType: false,
                processData: false,
                success: function(data) {
                console.log(data);
                if(data == "success"){
                    $("#success_message").show();
                    $("#success_message").fadeOut(4000);
                }
               },
             error:function(exception){
             alert('Exeption:'+exception);
            }
        });  */

    });


});

Put all the validation: 放入所有验证:

$('#SubmitForm).validate({
    // validation rules
});

and after that initialize the validation function like: 然后初始化验证函数,例如:

if($('#SubmitForm).valid())
{
    // make ajax() call here
}

Try this in your code 在您的代码中尝试

 submitHandler: function() {
            /*ajax request*/
        }

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

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