jQuery验证远程验证不起作用
问题描述:
我不确定自己在做什么错.我正在使用Jquery.Validate插件,它具有一个远程字段,所以我这样做了:
I am not sure what I am doing wrong. I am using the Jquery.Validate plugin and it has a remote field, so I did this:
$("#mainForm").validate(
{
rules:
{
UserName:
{
required: true
,remote: "Test"
}
,messages:
{
UserName:
{
remote: "UserName has already been chosen. Please choose another one"
}
}
}
所需的工作正常.是有问题的遥控器.我正在使用asp.net MVC,并且路径正确-命中了我的方法
The required works fine. It's the remote that has the problem. I am using asp.net MVC and the path is right - it hits my method
public bool Test(string userName)
{
return false;
}
根据萤火虫它返回false,但jquery.validate没有启动.我正在使用1.5.5版的jquery.validate和jquery 1.3.2
It returns false according to firebug yet jquery.validate does not kick in. I am using Version 1.5.5 of jquery.validate and jquery 1.3.2
我想念什么?
答
我也被这个迷住了.
您需要返回一个true或false的Json对象,请参见下文:
You need to return a Json object with true or false, see below:
public ActionResult IsValidField()
{
String the_field = httpContextService.Request["Field_To_Test"];
if (the_field == another_value)
return Json(true);
else
return Json(false);
}