0

我的 Jquery 验证器 ( http://bassistance.de/jquery-plugins/ ) 插件 submitHandler 函数有问题。表单验证正确,无效处理程序消息正确触发,但 submitHandler 函数不会正确触发,ajaxSubmit 函数也不会正确触发。有人看到我做错了什么吗?任何帮助都会受到欢迎。

<script type="text/javascript">
$(document).ready(function() {
var submitMessage     = $('#submit-message'),
    messageContainer  = submitMessage.find('span'),
    loading           = $('#loading');

function showSuccess(message) {
    messageContainer.text(message)
    messageContainer.attr('class', 'success');
  }
function showFailure(message) {
    messageContainer.text(message)
    messageContainer.attr('class', 'failure');
}
$("#contact-form-info").validate({
  rules: {
    contact_Name: {
      minlength: 2,
      maxlength: 50,
      required: true
    },
    contact_Foretag: {
      minlength: 1,
      maxlength: 50
    },
    contact_Email: {
      required: true,
      email: true
    },
    contact_Subject: {
      required: true,
      minlength: 5,
      maxlength: 50
    },
    contact_Message: {
      required: true,
      minlength: 10,
      maxlength: 5000
    }
  },
  submitHandler: function(form) {
        var options = {
            beforeSubmit: function() {
                loading.show();
            },
            success: function() {
                showSuccess('Thank you! Your email has been submitted.');
                form.reset();
                loading.hide();
            },
            error: function() {
                showFailure("We're sorry, your email could not be sent. Please try again later.");
                loading.hide();
            }
        };
        $(form).ajaxSubmit(options);
     return false;

    },
    invalidHandler: function() {
        showFailure('There were some problems with your submission.');
    }
 });
});
</script>

这是我在 jsFiddle 中的代码。http://jsfiddle.net/JwNmK/

4

1 回答 1

2

OP的评论

“当我提交一个有效的表单时,它作为一个‘正常’表单提交,我被重定向到 process.php 页面”

使用. _ return false_submitHandlerajax

submitHandler: function (form) {
    // your ajax
    return false;
},
于 2013-04-19T15:35:02.540 回答