表单不使用Position Absolute中的validationEngine()插件提交

时间:2011-05-26 15:10:56

标签: jquery jquery-validation-engine

我正在使用validationEngine jQuery插件来验证我的webform。验证完成后,我想通过ajax提交表单。表单提交正常,没有附加验证引擎插件。验证有效,但是ajax在完成后不会触发提交表单。我做错了什么:

jQuery("form#sign-up").validationEngine({
    onValidationComplete: function () {
        var first = $("input#first").val();
        var last = $("input#last").val();
        var email = $("input#email").val();
        var pass = $("input#pass").val();



        var dataString = 'first=' + first + '&last=' + last + '&email=' + email + '&pass=' + pass;

        //to send the ajax request  
        $.ajax({
            type: "POST",
            url: "./register.php",
            data: dataString,
            success: function () {
                $('#sign-up').html("<div id='message'></div>");
                $('#message').html("<h2>Thanks!</h2>")
                    .append("<p>We'll send you an email when infoFree is ready to Rock n' Roll.</p>")
                    .hide()
                    .fadeIn(500, function () {
                    $('#message').append("<img id='checkmark' src='./assets/images/check.png' />");
                });
            }
        });
    }
});

1 个答案:

答案 0 :(得分:0)

validationengine阻止表单实际提交,因此不要在onValidationComplete中执行所有操作,只需将其全部移动到提交表单的函数中:

$(document).ready(function() {
  $("form#sign-up").validationEngine();
  $("form#sign-up").submit(function(){
    var first = $("input#first").val();
    var last = $("input#last").val();
    var email = $("input#email").val();
    var pass = $("input#pass").val();

    var dataString = 'first='+ first + '&last=' + last + '&email=' + email + '&pass=' + pass;

    //to send the ajax request  
    $.ajax({
      type: "POST",
      url: "./register.php",
      data: dataString,
      success: function() {
        $('#sign-up').html("<div id='message'></div>");
        $('#message').html("<h2>Thanks!</h2>")
        .append("<p>We'll send you an email when infoFree is ready to Rock n' Roll.</p>")
        .hide()
        .fadeIn(500, function() {
          $('#message').append("<img id='checkmark' src='./assets/images/check.png' />");
        });
      } 
    });
  });
}); // ready

〜Cyrix的