Asp.Net MVC - JQuery 远程验证
我得到了以下 JQuery 验证脚本:
<script type="text/javascript">
$(document).ready(function() {
$("#myForm").validate({
rules: {
"Content": {
required: true,
rangelength: [20, 1000],
remote: {
url: "/RemoteValidation/IsValidContent",
timeout: 2000,
type: "post"
}
}
},
messages: {
"Content": {
required: "* ...A",
rangelength: "* ...B",
remote: "* ...C"
}
}
});
});
以及以下控制器:
public class RemoteValidationController : Controller
{
[HttpPost]
public virtual JsonResult IsValidContent(MyObject object)
{
return new JsonResult
{
Data = true
};
}
}
它仅用于测试目的,它始终返回 true。
我遇到的问题如下。我看到错误消息 (...C) 出现 1 秒然后消失...
我不知道如何解决...
为什么它会出现...它不应该出现...
更新
问题仅当我在文本区域中写得很快时才会出现。如果我写得慢的话,它就不会出现。我的猜测是,在我的打字之间,验证没有时间进行验证,默认情况下,它会显示错误?
无论如何,我可以改变这种行为吗?
I got the following JQuery validation script :
<script type="text/javascript">
$(document).ready(function() {
$("#myForm").validate({
rules: {
"Content": {
required: true,
rangelength: [20, 1000],
remote: {
url: "/RemoteValidation/IsValidContent",
timeout: 2000,
type: "post"
}
}
},
messages: {
"Content": {
required: "* ...A",
rangelength: "* ...B",
remote: "* ...C"
}
}
});
});
And the following controller :
public class RemoteValidationController : Controller
{
[HttpPost]
public virtual JsonResult IsValidContent(MyObject object)
{
return new JsonResult
{
Data = true
};
}
}
It's only for test purpose, its always return true.
The problem I got is the following. I see the error message (...C) that appears for 1 second and that disapear...
I don't know how to solve that...
Why it appears... it's should never appear...
UPDATE
The problem only appear if I write really quickly in the textarea. If I write slowly, it's doesn't appear. My guess is that between my typing, the validation haven't no time to validated, and by default, it's show the error ?
Anyway, I can change this behavior ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在键入时禁用验证,但只能在提交表单之前禁用:
You could disable validation when typing but only before submitting the form: