我使用 bootstrap-validator(http://1000hz.github.io/bootstrap-validator),如果 ajax 请求成功并且状态为“ok”,则需要显示错误消息。(可以说客户存在)。
如何返回 ajax 请求并使其与验证器一起使用?这是当前代码:
$('form').validator({
custom: {
business: function($el) {
var input_value = $el.val();
if(input_value.length > 5){
var result2;
$.ajax({
type: 'GET',
url: '/customers/'+input_value,
dataType: 'json',
success: function(data){
(data.status == 'ok' ? $(".nahtavad").prop('disabled', true) : $(".nahtavad").prop('disabled', false));
// if i return here it does nothing and does not display error.
return 'This customer exits'
}else {
$(".nahtavad").prop('disabled', false);
}
},
error: function (err) {
$("input[type='submit']").prop('disabled', false);
$(".nahtavad").prop('disabled', false);
}
});
}
}
}
});