2009-08-08 109 views
1

我不知道我在做什么错。我现在用的是Jquery.Validate插件,它具有远程现场,所以我这样做:Jquery验证远程验证不起作用

$("#mainForm").validate(
    { 
     rules: 
     { 
      UserName: 
      { 
       required: true 
       ,remote: "Test" 
      } 
     ,messages: 
     { 
      UserName: 
      { 
       remote: "UserName has already been chosen. Please choose another one" 
      } 
     } 

    } 

所需的优良工程。有问题的是遥控器。我使用asp.net MVC和路径是正确的 - 它击中我的方法

public bool Test(string userName) 
{ 
    return false; 
} 

它根据萤火但jquery.validate不踢在我使用jquery.validate的1.5.5版本返回false。和jquery 1.3.2

我错过了什么?

回答

2

我被这个也抓到了。

您需要返回与true或false JSON对象,见下图:

public ActionResult IsValidField() 
    { 
     String the_field = httpContextService.Request["Field_To_Test"]; 

     if (the_field == another_value) 
      return Json(true); 
     else 
      return Json(false); 
    } 
+0

这是真的搞砸了。我发现在jQuery经过数小时的奋斗后,返回plan布尔值true/false的dataFilter被$ .parseJSON方法拒绝。现在解决方案似乎返回$ .toJSON(true)或返回$ .toJSON(false) – sakhunzai 2011-07-01 14:30:04