表单未使用绝对位置的validationEngine()插件提交
我正在使用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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
验证引擎会阻止表单实际提交,因此不必在 onValidationComplete 中执行所有操作,只需将其全部移至表单提交时的函数中即可:
~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:
~Cyrix