This is what I have so far. I'm trying to parse json file and grab img path and width get the return for each record in GETJson json and append to "Gallery" Inside an unordered list with a class named thumbs. So instead of having several lines of code "li img src= path of images" width= " in the html, I could just read json file and populate this.
My json looks like this:
[ { "image":"sliders/img/img1.jpg", "width":400 }, { "image":"sliders/img/img2.jpg", "width":400 }, ]
Here's the Getjson logic.
<script type="text/javascript">
$().ready(function(){
$.getJSON('fred.json', function(data) {
//Collection of li elements
var items = [];
$.each(data, function(key, val) {
items.append('<li><img src="' + val.image + '+ '" width="'
+ val.width + '" /></li>');
});
$('<ul/>', {
'class': 'thumbs',
html: items.join('')
}).appendTo('#Gallery');
//Once all ul are created call the gallery function
$('#Gallery').flickrGallery();
});
});
</script>
Thank You for any help
I incorrectly type the img name in the json file description. I have it spelled out correctly. When I run the html two things happen. The images do not show at all. Everything else appears background etc. for the images does appear. When I do an alert(items) I can see the li populating. Basically, I have a div id=Gallery and and ul inside the div named thumbs_1 with class =thumbs
div id = GALLERY
ul id="thumbs_1" class="thumbs"
li> "img src="images/image_11.jpg" width=600" there are a total of 11 lines like this. Instead of having this harcoded in the HTML I just want to dynamically place the same line of code using GetJson. Then once the DIV is populated
use this
$().ready(function(){ $('#Gallery').flickrGallery({
which calls a specfic function that has been developed already and works to creates a photo gallery. Sorry for any confusion and Thank you for already helping out.