I have a json file that I am trying to access using the following jquery function.
$.ajax({
type: 'GET',
url: '/data/coffee.json',
dataType:'json',
success: function(data) {
let widget = show(data);
$("#Meals").html(widget);
}
});
function show(data) {
let statusHtml = '<ul>';
$.each(data.prices, function(i, meal){
statusHtml += '<li> name: '+ meal.item + '</li>';
statusHtml += '<li> price: '+ meal.price + '</li>';
});
statusHtml += '</ul>';
return statusHtml;
}
The data I am trying to access is as follows:
[
{
"shopName": "The Coffee Connection",
"address": "123 Lakeside Way",
"phone": "16503600708",
"prices": [
{
"item": "Cafe Latte",
"price": 4.75
},
{
"item": "Flat White",
"price": 4.75
},
{
"item": "Cappucino",
"price": 3.85
},
{
"item": "Single Espresso",
"price": 2.05
},
{
"item": "Double Espresso",
"price": 3.75
},
{
"item": "Americano",
"price": 3.75
}
]
}
]
I have tried to console.log('success', data); and this returns the prices array in the console. But for some reason it is not showing up when I run this code. Any help would be appreciated.