阻止Javascript多次提交表单
我有一个要提交解析的表单,在我添加了一些客户端验证之后,它会继续双重提交到数据库 我已经阅读了关于这个主题的其他一些堆栈文章,并调整了我的代码,但它仍然在发生(我刚刚开始学习JS)。任何关于如何解决此问题的建议都将不胜感激。谢谢阻止Javascript多次提交表单,javascript,jquery,Javascript,Jquery,我有一个要提交解析的表单,在我添加了一些客户端验证之后,它会继续双重提交到数据库 我已经阅读了关于这个主题的其他一些堆栈文章,并调整了我的代码,但它仍然在发生(我刚刚开始学习JS)。任何关于如何解决此问题的建议都将不胜感激。谢谢 $(document).ready(function() { Parse.initialize("XXXX", "XXXX"); $('#commentForm').bootstrapValidator({ feedbackIcons: {
$(document).ready(function() {
Parse.initialize("XXXX", "XXXX");
$('#commentForm').bootstrapValidator({
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
username: {
message: 'The username is not valid',
validators: {
notEmpty: {
message: 'The username is required and cannot be empty'
}
}
}
}
});
$("#commentForm").on("submit", function(e) {
$(this).submit(function() {
return false;
});
e.preventDefault();
console.log("Handling the submit");
//add error handling here
//gather the form data
var data = {};
data.username = $("#username").val();
data.password = $("#password").val();
data.passwords = $("#password").val();
data.email = $("#email").val();
// data.area = $("#area option:selected").val();
// data.comments = $("#comments").val();
var comment = new Parse.User();
comment.save(data, {
success:function() {
console.log("Success");
alert("Thanks for signing up!");
},
error:function(e) {
console.dir(e);
}
});
});
});
这可能是因为表单提交函数中的第二个
submit
函数,所以请尝试删除:
$(this).submit(function() {
return false;
});
这就是我在阅读StackOverflow时添加的内容,以防止提交再次发生。我又把它拿了出来,它仍然是双重提交。