2

I have been trying to create a check user system to prevent duplicates. The code below returns true or false correctly but for some reason it is not triggering the error class system to display the error.

JavaScript

$(document).foundation({
abide : {
    validators: {
        checkUser: function(el, required, parent) {
            var result = $.ajax({ type: "GET", url: "../functions/checkUsername.php",data:{'username':el.value}, async: false }).responseText;
            return result;
        }
    }
}
});

The PHP script checks the username and returns true or false.

If anyone knows what I am doing wrong I will be grateful.

zer00ne
  • 41,936
  • 6
  • 41
  • 68
James
  • 702
  • 2
  • 15
  • 39
  • 1
    Does your script literally prints true/false? You are getting a string that it will always be true unless it's an empty string. `'false'` is not false. – MinusFour Aug 01 '15 at 18:50

1 Answers1

0

The call to $.ajax() returns a promise because it's non blocking. I don't think that Abide handles promises: maybe it just expects true or false, and since your result can be coerced to true (it's neither null nor undefined) it thinks user input is valid.

Raffaele
  • 20,627
  • 6
  • 47
  • 86