我使用bassistance.de的jQuery验证程序插件(1.11)并通过php提交。现在,我在javacript代码的末尾的提交处理程序中添加了一个ajax调用,但是该调用不起作用,firebug控制台也不存在。
案例1 如果我在网站的开头放置了ajax调用,它可以工作,但是不再可以看到验证器插件。
案例2 如果我将调用放入提交处理程序中,则该调用不存在,并且表单由php提交。
案例3 如果我将代码放在页面的末尾,则联系表仍由php提交。
这是ajax调用:
$("#contactform").submit(function(e){
e.preventDefault();
$.ajax({
type: "POST",
url: "formfiles/submit.php",
data: $(this).serialize(),
success: function() {
$('#contactform').html("
$('#message').html("
Your request is on the way!
").append("
someone
").hide()
.fadeIn(1500, function() {
$('#message').append("");
});
}
});
return false;
});
有人知道怎么了吗?
预先感谢您提供的任何帮助,为此我全力以赴。
编辑 为了更好地理解问题,这里是完整的javascript
$(document).ready(function(){
$("#contactform").validate();
$(".chapta").rules("add", {maxlength: 0});
var validator = $("#contactform").validate({
ignore: ":hidden",
rules: {
name: {
required: true,
minlength: 3
},
cognome: {
required: true,
minlength: 3
},
subject: {
required: true,
},
message: {
required: true,
minlength: 10
}
},
submitHandler: function(form) {
$("#contactform").submit(function(e){
e.preventDefault();
$.ajax({
type: "POST",
url: "formfiles/submit.php",
data: $(this).serialize(),
success: function() {
$('#contactform').html("
$('#message').html("
Your request is on the way!
").append("
someone
").hide()
.fadeIn(1500, function() {
$('#message').append("");
});
}
});
return false;
});
},
});
});
编辑2
选择器和所有其他似乎都很好。