$("#contactForm").validator().on("submit", function (event) {
if (event.isDefaultPrevented()) {
// handle the invalid form...
formError();
submitMSG(false, "你把表格填好了吗 ?");
} else {
// everything looks good!
event.preventDefault();
submitForm();
}
});
function submitForm(){
// Initiate Variables With Form Content
var name = $("#name").val();
var email = $("#email").val();
var mobile = $("#mobile").val();
$.ajax({
type: "POST",
dataType: "json",
url: "/form/",
data: $('#contactForm').serialize(),
success: function (result) {
if (result.code == '0') {
alert("提交失败:请检查信息是否完整,格式是否正确!");
} else {
alert("提交成功!");
// window.location.href='/';
window.location.reload();
}
},
error : function() {
alert("网络异常!");
}
});
}
function formSuccess(){
$("#contactForm")[0].reset();
submitMSG(true, "Message Submitted!")
}
function formError(){
$("#contactForm").removeClass().addClass('shake animated').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function(){
$(this).removeClass();
});
}
function submitMSG(valid, msg){
if(valid){
var msgClasses = "h5 text-center tada animated text-success mt-3";
} else {
var msgClasses = "h5 text-center text-danger mt-3";
}
$("#msgSubmit").removeClass().addClass(msgClasses).text(msg);
}
}(jQuery)); // End of use strict
广州万锐照明设备有限公司 All rights reserved.