0

I have to create a slideshow out of image paths that I store in a database and create the array using PHP, calling it with the JQuery ajax function. I can successfully call the array, however I am having trouble getting the Javascript slideshow to work. Here is my script:

window.onload = slideshow(0);

var i;

function slideshow(dir) {

var d = dir;
i =+ d;

$.ajax({
    url: "comiccheck.php",
    datatype: "json",
    success: function(data, textStatus, xhr) {
        data = JSON.parse(xhr.responseText);
        if(i < 0) {
            i = data.length - 1;
        }
        var comic = data[i];
        $('#comic').replaceWith("<img id='comic' src='" + comic + "' alt='comic' />");  
    }
});
}

The function slideshow(dir) is being called in the HTML when the user clicks on an arrow button, returning 1 or -1, depending on the direction. Right now the buttons will only advance the image once in each direction, but not any further. Please let me know of any questions or comments you might have on the issue, thank you.

2 Answers 2

4

Is the i =+ d intended? Shouldn't it be i += d ?

Sign up to request clarification or add additional context in comments.

1 Comment

haha wow. thank you. before when I switched it, I would get an error, but that's because I never defined i as a number in the first place. I feel stupid.
-2

Try puting the window.onload = slideshow(0); after the function declartaion, you can't call a function before you declared it.

1 Comment

Actually you can call a function from wherever.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.