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.
The call to
$.ajax()
returns a promise because it's non blocking. I don't think that Abide handles promises: maybe it just expectstrue
orfalse
, and since your result can be coerced totrue
(it's neithernull
nor unde
fined) it thinks user input is valid.