jQuery Validation Plugin 1.9.0 ..我想提交不会在页面有效时重新加载页面

时间:2013-10-08 15:50:33

标签: php jquery mysql ajax validation

$("#da-ex-validate2").validate({
                rules: {
                    details: {
                        required: true,
                        rangelength: [1, 500]
                    },
                    editor1: {
                        required: true,
                        minlength: 1
                    },
                    title: {
                        required: true,
                        rangelength: [1, 100]
                    },
                    SlideDeckPhoto: {
                        required: "#iButton:checked",
                        accept: ['.jpeg', '.png', '.jpg', '.gif']
                    },
                    min1: {
                        required: true,
                        digits: true,
                        min: 5
                    },
                    max1: {
                        required: true,
                        digits: true,
                        max: 5
                    },                          
                    submitHandler: function(form) {
                        $(form).ajaxSubmit();
                    },
                    range1: {
                        required: true,
                        digits: true,
                        range: [5, 10]
                    }

                },
                invalidHandler: function (form, validator) {
                    var errors = validator.numberOfInvalids();
                    if (errors) {
                        var message = errors == 1
                        ? 'You missed 1 field. It has been highlighted'
                        : 'You missed ' + errors + ' fields. They have been highlighted';
                        $("#da-ex-val2-error").html(message).show();
                    } else {
                        $("#da-ex-val2-error").hide(); // it's not work !!! and the page is reload !!
                    }
                }
            });

我还想将表单值保存到MySql而不重新加载页面。 请帮忙 !我看了这么多帖子,尝试了很多东西! 如果您输入代码请告诉它放在哪里.. BTW我的表单有很少的输入字段和文件输入字段。 请帮助!

2 个答案:

答案 0 :(得分:0)

从提交处理程序返回false

submitHandler: function(form) {
    $(form).ajaxSubmit();
    return false;
}

答案 1 :(得分:0)

这是我的解决方案,把它放在invalidHandler之后:

            submitHandler: function(form) {
                var dataString = $('#YourFormID').serialize();
                $.ajax({
                    type: 'POST',
                    url: 'yourpage.php',
                    data: dataString,
                    success:  function() {
                        $('#YourErrorDivID').hide();
                        $('#YourSuccessDivID').html("Your Message").show();
                    }
                });
            }