以下是我的表单以及用于提交数据的jquery / ajax脚本。我遇到的问题是“ submitHandler”无法正常工作。通过向用户显示错误消息,所有工作都可以进行,但是没有数据发布。我在控制台中没有看到任何错误。谁能看到我哪里出问题了。
表格:
<form method="" action="" name="Form1" id="Form1" autocomplete="off" >
// all the form fields
</form>
脚本:
$("#Form1").validate({
rules: {
board: {
required: true,
},
PromotionName: {
required: true,
},
FromDate: {
required: true,
},
FromTimeH: {
required: true,
},
FromTimeM: {
required: true,
},
ToDate: {
required: true,
},
ToTimeH: {
required: true,
},
ToTimeM: {
required: true,
},
},
messages: {
board: {
required: "Please select a display board",
},
PromotionName: {
required: "Please enter the promotional name",
},
FromDate: {
required: "Please select the start date",
},
FromTimeH: {
required: "Please select the start time hours",
},
FromTimeM: {
required: "Please select the start time mins",
},
ToDate: {
required: "Please select the finish date",
},
ToTimeH: {
required: "Please select the finish time hours",
},
ToTimeM: {
required: "Please select the finish time mins",
},
},
submitHandler: function(form) {
var form_data = new FormData(document.getElementById("Form1"));
$.ajax({
url: "insert_new_promotion.php",
data: form_data,
processData: false,
contentType: false,
type: "POST",
success: function(data,status){
alert(data);
}
}).done(function( data ) {
console.log(data);
window.location.reload();
});
return false;
}
});
非常感谢您的宝贵时间。
答案 0 :(得分:0)
我解决了我的问题。我忘了包括“ $(document).ready”。