Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying to use json file and Getjson to populate <li> with img src
    text
    copied!<p>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.</p> <p>My json looks like this:</p> <blockquote> <p>[ { "image":"sliders/img/img1.jpg", "width":400 }, { "image":"sliders/img/img2.jpg", "width":400 }, ]</p> </blockquote> <p>Here's the Getjson logic.</p> <pre><code>&lt;script type="text/javascript"&gt; $().ready(function(){ $.getJSON('fred.json', function(data) { //Collection of li elements var items = []; $.each(data, function(key, val) { items.append('&lt;li&gt;&lt;img src="' + val.image + '+ '" width="' + val.width + '" /&gt;&lt;/li&gt;'); }); $('&lt;ul/&gt;', { 'class': 'thumbs', html: items.join('') }).appendTo('#Gallery'); //Once all ul are created call the gallery function $('#Gallery').flickrGallery(); }); }); &lt;/script&gt; </code></pre> <p>Thank You for any help</p> <p>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</p> <blockquote> <p>div id = GALLERY<br> ul id="thumbs_1" class="thumbs"<br> 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<br> use this<br> $().ready(function(){ $('#Gallery').flickrGallery({<br> 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.</p> </blockquote>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload