because of the async of javascript I normally use callback functions
to do the value passing. So instead of return true or return false in
a ajax function, it's better to call a function with the true or false
as a parameter.

Just my two cents ;)

On 12 dec, 20:24, Jojje <jojjsus_chr...@hotmail.com> wrote:
> How deep in the scope can you go in nested functions and still return
> a value? For example:
>
> $.validator.addMethod('userCheck', function (value) {
>     $.ajax({
>         type: "POST",
>         url: "_scripts/send_message.php",
>         data: "action=checkuser& username=" + value,
>         success: function(msg) {
>             if (msg) {
>                 return false;
>             }
>             else {
>                 return true;
>             }
>         }
>     });
>
> },"");
>
> Why is´nt this working?
>
> If i do this:
>
> //Global
> var result;
>
> $.validator.addMethod('userCheck', function (value) {
>     $.ajax({
>         type: "POST",
>         url: "_scripts/send_message.php",
>         data: "action=checkuser& username=" + value,
>         success: function(msg) {
>             if (msg) {
>                 result = false;
>             }
>             else {
>                 result = true;
>             }
>         }
>     });
>     return result;
>
> },"");
>
> i get the value back but it does not work properly, It gets the value
> from the textfield but on keyup it's always one letter short... so i
> have to type one more letter to get the right value. I´m stuck on this
> so any help would be greatly appreciated! :)
>
> Thanks in advance
>
> George

Reply via email to