Hi Vic, the global anArray works fine see: http://jsbin.com/ukesa/edit
The problem is that you have to wait until the ASYNCHRONOUS callback of your get() function has been called. 1) minor style remark You could declare anArray outside of the ready function with a var statement. This makes the code more readable IMHO, but it's just personal style. var anArray = [ ]; $(function () {...} 2) wait for the callback Try the jsbin link. The alerts The first alert is empty, even it is called after the get functions. The second alert is falled from a callback and has one payload data. The third alert is falled from the other callback and has 2 data. When you press the "show" button the current data of anArray are shown. If you press it _before_ the callbacks are finished you will see that the alert is empty. But for that you would have to be really fast. I doubt that this is possible with a reasonable fast Internet connection :-) If you press the button _after_ the callbacks has been called, you will see that anArray has some data. 3) wait for more than one callback (again in the jsbin example) Use a global counter that is increased in every callback. (For simplicity, the example is for 2 callbacks -> simply replace 2 by 3 for your problem.) If the counter is 2, call your process (showGraph() ) function from _every_ callback. Just remember the first A in AJAX -> Asynchronous, so you cannot say which callback is executed as first, second or last. by(e) Stephan 2009/2/20 Vic <vics...@gmail.com>: > > Thanks Stephan for jumping in. > > anArray near the end of the callback function within $.get() now has > the correct values I want from the csv file. I understand what you > said about doing everything from the callback function. But in my case > I have 3 csv files to open and I'd like to perform some graphing > functions (via jQuery plugin flot) after all 3 have been read. > > What's unusual (at least to me anyway) is that the global variable > anArray never gets filled with the csv file values outside of the > callback function within $.get(). So I think I must be doing something > wrong. > > Thanks again in advance, > Vic > > On Feb 20, 5:33 am, Stephan Veigl <stephan.ve...@gmail.com> wrote: >> Hi Vic, >> >> I guess the problem is that get is an asynchronous function. So >> anArray exists outside of your get-callback function (since you use it >> as global variable) but the value is not set when the get function >> returns since your callback has not been executed yet. >> So whenever you access anArray you have to take care that it's already >> filled with the right values. The easiest way would be to do >> everything in your callback function, or write a data handling >> function you call from the callback function if you want to make your >> code more readable and modular. >> >> by(e) >> Stephan >> >> 2009/2/20 Vic <vics...@gmail.com>: >> >> >> >> > Hopefully this won't sound too silly, although it probably is. I've >> > been scratching my head about how to get 2 jQuery plugins to be aware >> > of the same array variable. >> >> > Situation: >> >> > $(function () { >> > anArray = [ ]; >> > // Instead of hardcoding the values in an array like below: >> > // anArray = [ [A,1], [B,2], [C,3] ]; >> > // I want to read it from a csv file >> > usinghttp://plugins.jquery.com/project/csv. >> > So I put in: >> > $.get("a1b2c3.csv", function(data) { >> > anArray = $.csv() (data); >> > alert(anArray); // this works just fine. File >> > is read. anArray is set. Everything's great. >> > }); >> >> > // but outside of the $.get function, anArray is undefined. And i >> > can't pass it out no matter what I try! >> >> > // ....... passing anArray to jQuery flot plugin to plot a graph, >> > among other things ...... >> >> > } >> >> > I'm sure I'll get a big "duh!" from someone on this mailing list. But >> > alas, I admit, I'm new to jQuery. >> >> > Thanks in advance, >> > Vic