Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/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
Php 如何在验证代码成功的过程中添加ajax代码_Php_Jquery_Ajax - Fatal编程技术网

Php 如何在验证代码成功的过程中添加ajax代码

Php 如何在验证代码成功的过程中添加ajax代码,php,jquery,ajax,Php,Jquery,Ajax,如何在验证代码成功的过程中添加ajax代码 <script type="text/javascript"> $(document).ready(function () { $("#footer-request-form").validate({ errorClass: 'has-error', success: "valid", errorPla

如何在验证代码成功的过程中添加ajax代码

<script type="text/javascript">
        $(document).ready(function () {

            $("#footer-request-form").validate({
                errorClass: 'has-error',
                success: "valid",

                errorPlacement: function (error, element) {
                    if(error.html()) error.appendTo(element.parent("div.form-group").addClass('has-error'));
                },

                unhighlight: function (element, errorClass, validClass) {
                    $(element).parents("div.form-group").removeClass('has-error');
                },
                success:function (label, element) {
                    $(element).removeClass("has-error");
                    $(element).parent().find('label.has-error').remove();
                },
                rules: {
                    name: {required: true},
                    phone: {phoneUS: true, required: true},
                    email: {required: true, email: true}
                },
                messages: {
                    phone: "Please enter a valid  phone number",
                    name: "Name is required!",
                    email: "Please enter a valid email address",
                }

            });
        });


    </script>

jQuery

$('#form').validate({

... your validation rules come here,

submitHandler: function(form) {
    jQuery.ajax({
        url: "contact_mail.php",
        data:'userName='+$("#name").val()+'&userEmail='+$("#email").val(),
        type: "POST",
        success:function(data){
        $("#mail-status").html(data);
        },
        error:function (){}
        });
}
});

jQuery

$('#form').validate({

... your validation rules come here,

submitHandler: function(form) {
    jQuery.ajax({
        url: "contact_mail.php",
        data:'userName='+$("#name").val()+'&userEmail='+$("#email").val(),
        type: "POST",
        success:function(data){
        $("#mail-status").html(data);
        },
        error:function (){}
        });
}
});

您可以创建新函数并在
success
上调用它。比如contactMail();用这种方法使用ajax函数,您可以创建新函数并在
success
上调用它。比如contactMail();并在这个方法中加入了我们的ajax函数