jQuery验证需要不工作,我想知道为什么
问题描述:
我想验证我的表单提交使用jqueryvalidation.js。 像jQuery验证需要不工作,我想知道为什么
HTTP Status 400 -
type Status report
message
description The request sent by the client was syntactically incorrect.
浏览器响应我用这个代码,但没有验证工作
<script type="text/javascript" src = "${contextPath }/static/js/jquery-migrate-1.4.1.min.js"></script>
<script type="text/javascript">
window.jQuery || document.write("<script src='${contextPath}/static/ace_admin1.3.1/assets/js/jquery.min.js'>"+"<"+"/script>");
</script>
<script type="text/javascript" src = "${contextPath }/static/js/jquery.validate.min.js"></script>
<script type="text/javascript">
$.validator.setDefaults({
submitHandler: function() {
alert("sumbit");
}
});
$(function() {
$("#subjectForm").validate({
rules: {
name : {
required: true,
},
testCount : {
required: true,
},
totalTime : {
required: true,
},
totalScore : {
required: true,
}
},
});
});
</script>
</head>
<body>
<form id="subjectForm " action="${contextPath }/teacher/testAddSubject" method="POST">
<p>add</p>
<p><label>subjectName</label><input name = "name" type ="text"/></p>
<p><label>Description</label><input name = "description" type ="text"/></p>
<p><label>number</label><input name = "testCount" type ="text"/></p>
<p><label>time</label><input name = "totalTime" type ="text"/></p>
<p><label>grade</label><input name = "totalScore" type ="text" /></p>
<button type="submit">submit</button>
</form>
</body>
</html>
我不知道什么地方出错,请帮忙me.it关于jQuery的版本和jQuery验证版本?
答
在年底删除多余的空间...
id="subjectForm "
它打破你的JavaScript。随着JavaScript的破碎,jQuery验证不会初始化。
(你会还需要包括jQuery的迁移后的jQuery)
至于你的状态码400:
客户端发送的请求在语法上是正确。
这与jQuery Validate插件完全没有关系。
400错误请求:请求无法通过服务器因语法错误的理解。客户端不应该在没有修改的情况下重复请求。
所以我建议你检查呈现 DOM在你的浏览器,并确保每个服务器请求(URL)适当地形成。另外,请在${contextPath}/teacher/testAddSubject
处查看您的服务器端脚本,并确保它没有损坏。
+0
谢谢你的帮助,我终于解决了这个问题。 –
首先:'$ {contextPath}'不是您的实际代码...... ***在浏览器中呈现的代码是JavaScript正在使用的代码。其次,你的问题与JavaScript无关。下面是状态码400的定义:*“由于格式错误,服务器无法理解请求,客户端不应该不加修改地重复请求。”* – Sparky