Garmaine Staff asked 2 years ago

I am checking if email already exists using parsley. However, it appears the validation is not function and the page is not being redirected through an ajax call. Here are my codes:

$(document).ready(function() {
  window.Parsley.addValidator('checkemail', {
    validateString: function(value) {
      return $.ajax({
        url: "ajax_action.php",
        method: "POST",
        data: {
          page: 'register',
          action: 'check_email',
          email: value
        dataType: "json",
        success: function(data) {
          return true;
        error: function(xhr, ajaxOptions, thrownError) {

<form method="POST" id="adminRegisterForm">
  <div class="form-group">
    <label>Email address</label>
    <input type="text" id="adminEmail" name="adminEmail" class="form-control" data-parsley-checkemail data-parsley-checkemail-message="Email address aslready exists" />

I will appreciate your assistance in knowing why the JS script is not validating.