如标题中所述,submitHandler未触发/到达,但验证工作正常。提交处理程序是正确的,但没有触发。
$(function () {
$("#form").validate({
rules: {
domain: {
required: true
},
playerClass: {
required: true,
}
},
submitHandler: function (form) {
var accountNumber = $("input#accountNumber").val();
var domain = $("input#domain").val();
var playerClass = $("input#playerClass").val();
var dataString = JSON.stringify([{
"accountNumber": accountNumber,
"playerClass": playerClass
}]);
//Save Form Data........
$.ajax({
type: "POST",
dataType: "json",
url: "/",
contentType: "application/json",
data: dataString,
success: function () {
$('.render-info').html("<div class='alert alert-success'>You've successfully built your player code</div>");
$(".player-code").show();
},
failure: function () {
alert(dataString);
$('.render-info').html("<div class='alert alert-failure'>Submission Error</div>");
}
});
$(".player-code").show();
}
});
});
jsFiddle:Link
答案 0 :(得分:0)
因为您没有真正的提交按钮。 div
不是按钮......
<div class="btn btn-default submit">Submit</div>
当表单有效时,您需要button
或input
type="submit"
来触发submitHandler
。
<input type="submit" class="submit" />
OR
<button type="submit" class="submit">Submit</button>