0
我有一個表單,我將它提交給Parse,並且在我添加了一些客戶端驗證後,它將雙向提交到數據庫。從多次提交表單中停止Javascript
我已經閱讀了一些關於這個主題的其他堆棧帖子,並調整了我的代碼,但它仍然在發生(我剛開始學習JS)。任何建議如何解決這個將不勝感激。謝謝!
$(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);
}
});
});
});
所以這是我從讀書的StackOverflow到再次發生停止提交補充。我再次拿出來,它仍然是雙重提交。 – 2014-10-09 02:16:40