【发布时间】:2015-03-08 23:11:09
【问题描述】:
我正在遵循 jQuery 验证页面中的默认示例,并且遇到以下错误:
Uncaught TypeError: undefined is not a function
在这一行:
$('form').validate().on('submit', function(e) {
当我尝试提交一个空表单时,我可以看到默认消息按预期触发,但是,当我提交填写的表单时,没有发送任何内容。
没有 .validate() 表单提交正常。
是什么原因导致此错误和完成的表单无法使用 .validate()?
html
<form id="form1" action="#" method="post">
<label>Name:</label>
<input type="text" minlength="2" name="name" required>
<label>Class Id:</label>
<input type="text" minlength="2" name="class" required>
<p><button type="submit">Submit</button></p>
</form>
<script src="../js/jquery-1.11.2.min.js" type="text/javascript"></script>
<script src="../js/jquery.validate.min.js" type="text/javascript"></script>
jquery
(function() {
$('form').validate().on('submit', function(e) {
e.preventDefault();
$.post('create.php', $(this).serialize(), function() {
console.log('Submission entered');
window.location = 'contact_form.html';
});
})
})();
【问题讨论】:
-
你真的应该学习the example on this page。您永远不会将
.submit()附加到.validate()方法。 stackoverflow.com/tags/jquery-validate/info
标签: jquery forms jquery-validate