0

please help me in solving how to store image in json file and how retrive it i have already tried . but i am not able to

$(document).ready(function () { var jsonURL = "data/data.json"; $.getJSON(jsonURL, function (json) { var imgList= ""; $.each(json.products, function () { imgList += '<li><img src= "' + this.imgPath + '"></li>'; }); $('#dvProdList').append(imgList); }); });
<div> <ul></ul> </div>

it here

1
  • what does your this in the each evaluates to? Commented Apr 12, 2016 at 8:03

1 Answer 1

1

Your code looks quite well. Just change your HTML

<div> <ul id="dvProdList"></ul> </div> 

And then in your javascript (check how each statement works in jquery):

 $.each(json.products, function (index, product) { imgList += '<li><img src= "' + product.imgPath + '"></li>'; }); $('#dvProdList').html(imgList); 

Make shure your image paths are ok and you are loading the json correctly.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.