Mailing List Archive
tlug.jp Mailing List tlug archive tlug Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][tlug] Variable scope in Javascript driving me nuts
- Date: Fri, 27 Aug 2010 01:29:11 +0900
- From: Dave M G <dave@example.com>
- Subject: [tlug] Variable scope in Javascript driving me nuts
- User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.11) Gecko/20100713 Thunderbird/3.0.6
TLUG, Arrgh! This just makes no sense to me. Here's my code: my function() { var valid = false; string = JSON.stringify(data); $.post('jsonhandler.php', {JSON: string}, checkResult, "json"); function checkResult(jsonDataReceived) { valid = jsonDataReceived.valid; console.log ("jsonDataReceived.valid = " + jsonDataReceived.valid); console.log ("valid inside checkResult = " + valid); } console.log ("valid OUTSIDE checkResult = " + valid); return valid; } When I run this, this is what I see in the console log: valid OUTSIDE checkResult = false jsonDataReceived.valid = true valid inside checkResult = trueShouldn't what happens inside the checkResult function set "valid" to true before I get to the "return valid" part?Any advice would be much appreciated. -- Dave M G
- Follow-Ups:
- Re: [tlug] Variable scope in Javascript driving me nuts
- From: Philipp Wollermann
- Re: [tlug] Variable scope in Javascript driving me nuts
- From: Romeo Theriault
Home | Main Index | Thread Index
- Prev by Date: Re: [tlug] Die, "Adobe Bridge Workspace File"! Die!
- Next by Date: Re: [tlug] Variable scope in Javascript driving me nuts
- Previous by thread: Re: [tlug] Japanese Vocabulary for Software Design and development.
- Next by thread: Re: [tlug] Variable scope in Javascript driving me nuts
- Index(es):
Home Page Mailing List Linux and Japan TLUG Members Links