What I want is for data retrieved from one function to be displayed in another . I was told that using a global variable would allow me to accomplish this What is the best way to store a value for use in a later function? I'm hearing global variables are evil.
Here is what I tried. http://jsfiddle.net/8j947/17/
When I try to display the global variable as an alert it comes back as undefined (which might not be viewable on jsfiddle). I’m thinking this is because the data isn’t actually getting stored, but I’ve only been coding for 3 weeks, so what do I know. If you guys could help me out by showing me what I did wrong or proposing an alternate solution that would be great.
Your alert function at the bottom is executing immediately after
getCrossDomainJsonis called, and before the callback function passed intogetCrossDomainJsonis called. Since thesomePropertyproperty is set inside the callback function, when you refer to it in the alert, it hasn’t actually been set yet.Give your alert function a name and call it somewhere else AFTER the callback function completes.