jquery远程发布和检索但不显示错误消息

时间:2018-05-30 07:36:14

标签: jquery

我正面临此验证但未发布错误消息,请帮助解决此问题。在em元素中,它会自动取为display: none

<div class="row">
  <div class="col-xs-10 col-sm-10 col-md-8 col-lg-6 col-xl-6">
    <label class="label-control bmd-label-static" style="font-family: CircularAirPro;color:#727272;font-size: 14px;">Email *</label>
    <div class="form-group">
      <div class="input-group">
        <input type="text" class="form-control" name="email_data" id="emailval">
      </div>
    </div>
  </div>
$("#regval").validate({
  rules: {
    email_data: {
      required: true,
      remote: {
        url: 'email_check.php',
        dataType: 'POST',
        data: {
          'email': function() {
            return $('#emailval').val();
          }
        }
      }
    },
  },
  messages: {
    email_data: {
      required: "email field required",
      remote: "Email already exist"
    }
  },
  errorElement: "em"
});

验证后,它返回false,但在它旁边,它在em中显示为none,但它必须显示错误消息。喜欢这个

<input type="text" class="form-control pending valid" name="email" id="emailval" aria-required="true" aria-invalid="false" aria-describedby="emailval-error">

未显示错误消息

1 个答案:

答案 0 :(得分:0)

remote: {
    url: 'email_check.php',
    **dataType: 'POST',**
    data: {
      'email': function() {
        return $('#emailval').val();
      }
    }
  }

而不是 dataType 需要替换类型

  remote: {
    url: 'email_check.php',
    type: 'POST',
    data: {
      'email': function() {
        return $('#emailval').val();
      }
    }
  }