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

Reply via email to