【发布时间】:2013-02-08 13:06:31
【问题描述】:
我正在使用 jQuery 验证插件,效果很好。
我希望能够在远程 ajax 失败时既显示消息又触发模式(示例中为alert())。我无法弄清楚如何做到这两点。现在,它按预期触发了 alert(),但还附加了错误消息“请修复此字段”,这应该是我自己的自定义错误消息。
这是我得到的:
$("#adresse-form").validate({
errorElement: "span",
rules: {
navn: {
required: true,
minlength: 5,
maxlength: 25
},
tlf: {
required: true,
digits: true,
minlength: 8,
remote: {
url: "/ajax/check_tlf",
type: "post"
}
}
},
messages: {
navn: "Field Name is required",
tlf: {
required: "Field tlf is required!",
remote: function () { // i want to add the message aswell, not just the alert
alert("failed - tlf is already taken!");
}
}
},
submitHandler: function(form) {
doSomethingGreatOnSuccess();
},
errorPlacement: function (error, element) {
error.appendTo(element.parent());
}
});
【问题讨论】:
标签: jquery ajax jquery-validate