我正在使用jQuery验证插件,它工作得很好。当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());
}
});
+1,干得好。也很好的详细答案。 – Sparky 2013-02-08 23:49:43