【问题标题】:bootstrap-validator custom validation and ajax request return on success/okbootstrap-validator 自定义验证和 ajax 请求返回成功/确定
【发布时间】:2018-06-29 05:56:56
【问题描述】:

我使用 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);
                    }
                });
              }
          }
      }
  });

【问题讨论】:

    标签: jquery ajax-request bootstrapvalidator-1000hz


    【解决方案1】:

    无法返回 ajax 请求,因此,在长度控制后添加了此检查,现在它可以正常工作了:

    if($(".nahtavad").is('[disabled]') === true){
       return 'Error';
    }
    

    【讨论】:

      猜你喜欢
      • 2015-12-04
      • 2018-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-30
      • 2011-11-17
      • 2014-08-25
      • 2014-04-06
      相关资源
      最近更新 更多