I will be getting a JSON response from a server
var imagesdata =
{
"images": [
{
"image": "JSON_images/popcorn.jpg",
"name": "Popcorn"
},
{
"name": "Ice creams",
"image": "JSON_images/icecream_cup.jpg"
},
{
"name": "Snacks & Corn",
"image": "JSON_images/puff_egg.jpg"
},
{
"image": "JSON_images/thumsup_can.jpg",
"name": "Soft Drinks"
}
]
}
for (var i = 0; i < imagesdata.images.length; i++) {
var imagename = imagesdata.images[i].image;
var name = imagesdata.images[i].name;
callImage(imagename, name);
}
function callImage(imagename, name) {
var divhtml = $('<div class="item">');
divhtml.append('<i><img class = "imgclss" id="' + name + '" src="' + imagename + '" alt=""/></i>');
divhtml.append('</div>');
}
With the above JSON Data i am showing the images dynmaically on the User Interface as shown below and the User Interface looks this way
My question is that in case a particular image is not found under the JSON_images , how can i show a default image ??