Hi Steven, Thank you for your reply but i'm not sure i understand what you mean? By having async set to false the script does wait for the value to come back from the server before executing the rest of the script (i can tell it does this because all the alerts i run to test it, run in the order i would expect). The return function is set in the success option of the $.ajax method which calls the returnUsernameBool function. Initially(see below), i had just one function but tried breaking it in two to see if that would give me some clue as to why it wasn't working
function checkIfUsername(o) { $.ajax({ type: "POST", url: ""+CI_ROOT+"index.php/admin/check_if_username", data: ({username: username.val()}), async: false, dataType: "json", success: function(data){ if(data.bool == true){ o.addClass('ui-state-error'); updateTips("Your username must be unique"); return false; } else{ return true; } } }); } //check id username already exsists bValid = bValid && checkIfUsername(username); On Aug 10, 11:25 am, Steven Yang <kenshin...@gmail.com> wrote: > aside from the fact that checkIfUsername does not have a return > ajax function is not going to waitwhen you finished calling $.ajax your > function has already ended(returned) > then when server responded your returnUsernameBool will be called but thats > already too late for your alert(bValid) > > thinking as $.ajax is creating another thread and your callback is run in it > might help (eventhough javascript is single threaded)