$("#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 = "h4 tada animated text-success";
} else {
var msgClasses = "h4 text-danger";
}
$("#msgSubmit").removeClass().addClass(msgClasses).text(msg);
}
}(jQuery)); // End of use strict
广州万锐照明设备有限公司 All rights reserved.