[jQuery] Re: can't return value after $.ajax call

2009-08-10 Thread Steven Yang
by using "var bool = true;"you made "bool" local to your callback and not to your "checkIfUsername" so "checkIfUsername" does not have a reference of bool you have to make bool local to checkIfUsername so you first declare "var bool" in checkIfUsername, then allow your callback to assign it a value

[jQuery] Re: can't return value after $.ajax call

2009-08-10 Thread robg
Thank you, that has worked. I tried exactly the same thing before because i though that returning the boolean from within the $.ajax method might not work. However instead of using "bool = true;" i was using "var bool = true;". Have you any idea why using the prefix of var would stop this worki

[jQuery] Re: can't return value after $.ajax call

2009-08-10 Thread Steven Yang
if thats the case try function checkIfUsername(o) { var bool; $.ajax({ type: "POST", url: ""+CI_ROOT+"index.php/admin/check_if_username", data: ({username: username.val()}), async: false, dataType: "json",

[jQuery] Re: can't return value after $.ajax call

2009-08-10 Thread robg
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

[jQuery] Re: can't return value after $.ajax call

2009-08-10 Thread Steven Yang
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