I am having difficulty trying to learn this concept.
I have a JSON file with a list of hospitals, their address, hours and phone.
I want to make an AJAX call from JSON data and list the data onto the screen.
I can only get the first hospital to list, when I try to list the address only the address lists.
How can I write this using a loop that will list the objects and their properties?
Can someone explain this to me, please?
Please help -- thank you in advance.
JSON --
https://api.myjson.com/bins/b29r7
JS --
var url = 'https://api.myjson.com/bins/b29r7';
$.ajax({
url: url,
method: 'GET',
}).done(function(result){
var data = result.surrey;
for(var i=0; i<data.length; i++){
$('#data').each(function(index, ele){
$(ele).html(data[index].hospital);
});
}
}).fail(function(err){
throw err;
});
HTML --
<p id="data"></p>