我正在使用 jQuery 远程验证来检查描述是否已被使用。
Description: {
required: true,
maxlength: 20,
remote: function () {
var newDescription = $("#txtDescription").val();
var dataInput = { geoFenceDescription: newDescription };
var r = {
type: "POST",
url: "/ATOMWebService.svc/DoesGeoFenceDescriptionExist",
data: JSON.stringify(dataInput),
contentType: "application/json; charset=utf-8",
dataType: "json",
dataFilter: function (data) {
var x = (JSON.parse(data)).d;
return JSON.stringify(!x);
}
};
return r;
}
},
我遇到的问题是,当用户没有修改文本框并返回时说描述已被使用,因为它在数据库中找到了它自己,就会发生这种远程验证。
那么是否可以仅在文本字段与原始字段不同时才运行远程验证?
我注意到 jQuery 所需的验证有一个 dependent 选项,但我无法让它与远程调用一起使用。
最佳答案
以下是使用 remote
和 depends
的解决方案:https://github.com/jzaefferer/jquery-validation/issues/431
关于jquery - 是否可以依赖 jQuery 远程验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9272149/