javascript - jQuery AJAX .each() not stopping -
not sure if title makes sense here's problem;
i use dropbox share family photos, trying put them html page in own div based on content.
i load them via json file looks this
[ { "birthday": "10" }, { "camping": "20" }, { "july fourth": "50" } ]
and using jquery .ajax load them
$(document).ready(function () { $.ajax({ url: 'events.json', success: function(response) { $.each(response, function() { $.each(this, function(name, photos) { $('#container').append('<div class="gallery" name="' + name + '"></div>'); $('div[name="' + name + '"').append(function() { ( var = 1; <= photos; i++) { if (i < 10) { $('.gallery').append('<a class="fancybox" rel="' + + '" href="' + name + '/0' + + '.jpg"><img class="img" src="' + name + '/0' + + '.jpg" /></a>'); } else { $('.gallery').append('<a class="fancybox" rel="' + + '" href="' + name + '/' + +'.jpg"><img class="img" src="' + name + '/' + + '.jpg" /></a>'); } } }); }); }); } }); $(".fancybox").fancybox(); });
it creates each div that's needed, instead of putting each in own stack
birthday contains "birthday, camping, july fourth"
camping contains "camping, july fourth"
july fourth contains itself
how go making not contain each category after it?
i've figured out how fix this, quite simple , total derp on end
i changed $('.gallery').append()s $(this).append()
also, know json wasn't great, have fixed that.
$.getjson("events.json", function(data) { $.each(data, function(index, d) { var name = d.name; var photos = d.count; $('#container').append('<div class="gallery" name="' + name + '"></div>'); $('div[name="'+name+'"]').append(function() { ( var = 1; <= photos; i++) { if (i < 10) { $(this).append('<a class="fancybox" rel="' + + '" href="' + name + '/0' + + '.jpg"><img class="img" src="' + name + '/0' + + '.jpg" /></a>'); } else { $(this).append('<a class="fancybox" rel="' + + '" href="' + name + '/' + +'.jpg"><img class="img" src="' + name + '/' + + '.jpg" /></a>'); } } }); }); });
Comments
Post a Comment