表单未使用绝对位置的validationEngine()插件提交

发布于 2024-11-09 21:39:54 字数 1188 浏览 3 评论 0原文

我正在使用validationEngine jQuery 插件来验证我的网络表单。验证完成后,我想通过 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' />");
                });
            }
        });
    }
});

I'm using the validationEngine jQuery plugin to validate my webform. Once the validation completes, I'd like to submit the form via ajax. The form submits fine without the validation engine plugin attached. The validation works, but the ajax is not firing to submit the form after it completes. What am I doing wrong:

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' />");
                });
            }
        });
    }
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

愁杀 2024-11-16 21:39:54

验证引擎会阻止表单实际提交,因此不必在 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

validationengine prevents the form actually submitting, so instead of doing everything inside onValidationComplete, just move it all into a function on submit of the form:

$(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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文