我想为表单使用validate js插件(没有刷新的联系表单)。我在下面找到了这段代码,其作者使用submitHandler
密钥通过AJAX和PHP发送电子邮件。值为function(form) { ... }
。你能告诉我form
里面function(form)
参数的用途是什么吗?作者甚至没有在该函数中使用它。
JS CODE:
$().ready(function() {
// validate the comment form when it is submitted.
$("#actualForm").validate({
focusInvalid: false,
onkeyup: true,
rules: {
// simple rule, converted to {required:true}
name: "required",
comment: "required",
email: {
required: true,
email: true
},
},
submitHandler: function(form) {
var name = $('input[name="name"]').val();
var email = $('input[name="email"]').val();
var comment = $('input[name="comment"]').val();
var params = {
"name": name,
"email": email,
"comment": comment,
};
console.log(data);debugger;
$.ajax({
url: 'email.php',
data: params,
type: 'POST',
dataType: json,
success: function (data) {
if (data.status) {
//Give success log to user
} else {
//Do something
}
}
});
}