Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I kind of already asked a similar question before: how to stop an array iteration if an index contains an inner array to iterate, then continue And the answer worked for what the project was, which was using parent child relation for the cycle. But now the client has made it a little more difficult by requesting that they could change the the slide show when they needed (php output to JSON of course).

I have a slideshow that is supposed to cycle then loop through "featured" projects info while fading in and out 1 or more images per project info before fading into the next project. Simple... But now I need the projects to come from JSON data. And not only that, the design has changed to where there is no longer a parent child relation between the info and its images.

I have tried every which way I can, from using .each() to using setTimeout/setInterval, but I am not sure, as usual, if I am even approaching this correctly. All I managed to do was to spit everything at once. Please do not resolve this for me. I just want constructive insight and a possible point in the right direction.

JSfiddle Here w/ the full html, json and css

jquery

$(document).ready(function() {

$.getJSON('data/data.json'), function(data) {

    $.each(data.projects, function(index, value) {
        var project = this;
        var info = '<p class="slideImg">' + this.info + '</p>';
        var url = '<a href ="' + this.url + '">' + this.url + '</a>';
        var images = [];

        console.log(info);
        console.log(url);

        // get project images
        $.each(project.gallery, function() {
            var image = '<img src="' + this.src + '" alt="' + this.alt + '">';
            images.push(image); // ??
            console.log(image);
        });

        console.log('----------------------------------------');

    });

});
share|improve this question
1  
What is the actual question?? What part of your code doesn't work? What error occurs? – Brad M 29 mins ago
Like I said. It just doesn't work no matter what I do. I am not sure if I am approaching this the right way. (RT) – JremyDeaton 21 mins ago
Never say something just doesn't work. Never. Break the problem down. Try each individual line by itself. Use console.log() at every step. Also, you are using getJSON() incorrectly. Look at the jQuery documentation and check that you pass/receive the parameters/data correctly. You are sending the "data" object...but then immediately redefine "data" as the object parsed from the JSON data from the server. – Brad M 19 mins ago
And why didn't you say that to begin with... Thank you. – JremyDeaton 10 mins ago
Actually it isn't defined right in the fiddle. The JSON comes from a file where the var "data" isn't defined. "data" is originally set as the parameter in the getJSON function. I wasn't sure how to set it up in fiddle as I stated in a comment that it was actually coming from a file. – JremyDeaton 6 mins ago

1 Answer

$.getJSON() method is not being passed the correct parameters. In your case, you should be supplying a url which will serve the JSON data. Also, you only need to pass parameters in your request necessary to get that specific JSON data.

Please see the documentation @ http://api.jquery.com/jQuery.getJSON/

share
See edit above. The jsfiddle is wrong. – JremyDeaton 9 secs ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.