On Mar 30, 2009, at 4:20 PM, iceangel89 wrote:
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; } }); }
This example will not work, unless you set the ajax option 'async' to false (which I would not recommend, because it locks the browser). It's because the function validate() returns right after the getJSON function, because the latter is asynchronous. But you already figured that out.
These sort of things are best done passing callbacks to the getJSON function, as the previous examples show.
Regards, -- Martijn.