James James - 4 years ago 183
Javascript Question

Foundation Abide with AJAX function

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.


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.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download