Welcome Guest, Not a member yet? Register   Sign In
[solved] don't understand javascript variable scope; now talking about validation plugin
#5

[eluser]Fabdrol[/eluser]
[quote author="noctrum" date="1295986631"]move the result declaration outside of the function.

Code:
var result = false;
function name_free(value, element) {
    if(something) {
        $.post('something', { foo: bar }, function(data) {
            if(data == 'true') result = true;
        }
    }
    console.log(result);
    return result;
}
[/quote]

That way false is returned every time, since return result; will be called before result can be set to true by $.post.

You should move whatever you want to do with result to within the callback function!


Messages In This Thread
[solved] don't understand javascript variable scope; now talking about validation plugin - by El Forum - 01-25-2011, 06:39 PM



Theme © iAndrew 2016 - Forum software by © MyBB