jQuery.validate plugin and ajax form submission

后端 未结 3 1415
谎友^
谎友^ 2021-01-03 01:34

I cannot for the life of me get this to work. The validation errors appear fine, I don\'t get syntax errors but nothing happens. The form just submits to the page. I can\'t

3条回答
  •  鱼传尺愫
    2021-01-03 02:14

    Take your submitHandler out of your rules :-)

    $("#contact").validate({
                            rules: {
                            name: {required: true},
                            email: {required: true},
                            subject: {requred: true}
                            },
                            submitHandler: function() {
                                $.ajax({
                                    type: "POST",
                                    url: "/contact/process.php",
                                    data: formSerialize,
                                    timeout: 3000,
                                    success: function() {alert('works');},
                                    error: function() {alert('failed');}
                                });
    
                                return false;
                            }
                        });
    

提交回复
热议问题