jQuery验证远程验证不起作用 [英] Jquery Validation remote validation not working

查看:97
本文介绍了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);
    }

这篇关于jQuery验证远程验证不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆