Monday, March 30, 2009

[jQuery] Re: How to access variable outside function

can i do this at all? i think maybe becos getJSON will be async, i
wont be able to do this?

btw, background is i am doing some validation. within this validation
i need to get some value from server

so i did

function validate() {
var validated = true;

// some validation
...

// get value from server
$.getJSON("url", function(json) {
if (...) {
validated = false;
}
});
}

On Mar 30, 10:09 pm, iceangel89 <iceange...@gmail.com> wrote:
> i sometimes do something like
>
> var i;
> $.getJSON("url", function (json) {
>    // update i
>    i = json.var;
>
> });
>
> how can i access the updated i outside the function(json)...?

No comments: