No, the scope of the data parameter is not the problem. The data parameter
is already in scope inside your click handler. (Michel, check the code
carefully - don't you agree? The click handler is nested inside the getJSON
callback.)

If it were broken in IE8 as well as IE7, then I would guess that you
probably have a trailing comma at the end of your data.items array. If you
have an array like [ 'a', 'b', ] then IE gives it a length of 3 with an
undefined element at the end. But that should affect IE8 the same as IE7.

But let's stop guessing. Get in there and have a look at the actual data.

The error is occuring on this line in your click handler:

        var aIndexBG = data.items[aIndex].background;

So add this code right before that line:

        alert( aIndex );
        alert( typeof aIndex );
        alert( data );
        alert( data.items );
        alert( data.items.length );
        alert( data.items[aIndex] );
        alert( data.items[aIndex].background );

What do the alerts say?

-Mike

On Tue, Nov 17, 2009 at 10:26 AM, roryreiff <roryre...@gmail.com> wrote:

> So I guess that is the problem then? How would I work towards a
> solution in making 'data' available to that .click() function?
>
> On Nov 17, 10:02 am, Michel Belleville <michel.bellevi...@gmail.com>
> wrote:
> > Oh, yeah, now I see.
> >
> > Of course data is probably not what you expect where you're reading it.
> Why
> > would it ? It's set in a callback as a function's parameter, it's not
> meant
> > to get out of the callback's scope, and even when it would, you don't
> know
> > when the callback is triggered, that can be right before, right after, a
> > month after, never, depending on how the AJAX call ends.
> >
> > Michel Belleville
> >
> > 2009/11/17 roryreiff <roryre...@gmail.com>
> >
> > > Could it have something to do with the 'data' variable not being
> > > available to the function that I have placed inside the $.getJSON
> > > call? Is there a way to force it to pass on/be available to my
> > > ppButton.click(...) function? This is all I can think of for now.
>

Reply via email to