jQuery远程验证与服务器生成的错误消息 [英] jQuery remote validation with server generated error message

查看:77
本文介绍了jQuery远程验证与服务器生成的错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Validation jQuery插件进行一些验证。我有一个服务,现在返回true和false,一切都很好。

I am using the Validation jQuery plugin to do some validation. I have a service which returns "true" and "false" right now and everything is great.

但是,我使用的错误信息是该名称已被采用。

However, the error message I am using is "That name is already taken."

我希望错误消息是该名称已经< a href =/ item?id = 543> take< / a>。其中项目ID是从服务器返回的内容。但我无法弄清楚如何从服务器返回任何东西,而不是单个true或false,并且仍然有验证工作。

I want the error message to be "That name is already <a href="/item?id=543"> taken</a>." where that item id is something returned from the server. But I can't figure out how to return anything from the server other than a single true or false and still have the validation work.

我知道我可以做名称xxx是使用JQuery.Format(名称{0}被采取)但我真的想要给现有项目的超链接,我不想更改项目页面接受名称而不是id。

I know I can do "The name xxx is taken" using JQuery.Format("The name {0} is taken") but I really want to give a hyperlink to the existing item, and I don't want to have to change the item pages to accept a name instead of an id.

推荐答案

验证插件已处理此问题,但调用类型为json ,所以你需要确保在引号中传递字符串(错误消息),如下所示:

The validation plugin handles this already, but the call type is "json", so you need to make sure the string (error message) is passed in quotes, like this:

"Error Message"

该插件将使用此作为显示的错误消息,方便吗? :)

The plugin will use this as the displayed error message, handy eh? :)

这篇关于jQuery远程验证与服务器生成的错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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