我正在使用JQuery Validation和Malsup的AJAX表单插件尝试AJAX我的联系表单,但表单根本没有提交(没有AJAX工作)。我是JS的新手,所以请耐心等待。这是我的剧本:
<script src="http://malsup.github.com/jquery.form.js" type="text/javascript"></script>
<script>
$(document).ready(function() {
// attach handler to form's submit event
$(".new-form").submit(function() {
// submit the form
$(this).ajaxSubmit();
// return false to prevent normal browser submit and page navigation
return false;
});
// validate signup form on keyup and submit
$(".new-form").validate({
submitHandler: function(form) {
$(form).ajaxSubmit();
},
rules: {
name: {
required: true,
minlength: 2
},
email: {
required: true,
email: true
},
message: {
required: true
}
},
messages: {
name: {
required: "Please enter your name",
minlength: "Your name must consist of at least 2 characters"
},
email: {
required: "Please provide a valid email address"
},
message: {
required: "Please provide a message"
}
}
});
});
</script>
我哪里出错?
答案 0 :(得分:1)
你应该看一下这个例子:http://malsup.com/jquery/form/#ajaxSubmit
添加此代码:
// attach handler to form's submit event
$(".new-form").submit(function() {
// submit the form
$(this).ajaxSubmit();
// return false to prevent normal browser submit and page navigation
return false;
});