Hi all!

I'm facing a problem, and it seems very unlogical that it doesn't
work.
I've written a function to switch some images on a clients website. It
takes images from an array, and displays them with some nice fades.

Now I'm trying to fetch these images using AJAX, initially from a text
file, later I'll fetch them from a php script which fetches them from
a database. The script outputs like this:

image1.png,image2.png,image3.jpg,image4.jpg,image5.png

in the script I use the following to split it into an array:

<code>

var splitted;
var path = 'uploads/slideshow/';

$.get('ajax.txt', function(data) {
    splitted = data.split(',');
    console.log(splitted); // outputs to firebug to check if GET
worked
});

var slide = $(elm).attr('slide');
var total = splitted.length;
var next = slide+1
var picture = splitted[next];

$(elm).fadeOut(1000, function() {
    $(elm).attr('slide', next).css('background', 'url('+path+picture
+')');
    $(elm).fadeIn(1000);
});

</code>

but somehow, the $.get() part outputs nicely to the console, but after
that console gives an error that total splitted.length cannot be
determined because splitted is undefined! quite strange isn't it?

I tried to remove the console.log(), tried to define the img array
before $.get() and populate it inside the $.get().
Nothing works! What should I do, and more important, why does it
behave like this?

thanks,

Fabian

Reply via email to