I want from the following code to retrieve the data of the json file but the problem is that if I press again the button I see twice the results. I changed the first append of my each loop to html but then only the last object of my json is loaded.
HTML :
<ul id="myorders"></ul>
<button type="button" id="add-order">Load the orders</button>
JS :
$("#add-order").click(function(){
$.getJSON('API/orders.json', function(data){
$.each(data, function(i, order){
$("#myorders").append("<p><li> id: " + data[i].order.id + "</li>");
$("#myorders").append("<li> Name: " + data[i].order.name + "</li>");
$("#myorders").append("<li> Drink: " + data[i].order.drink + "</li></p>")
});
});
});
Data example :
[{ "order":{"id": "1",
"name": "Bill",
"drink": "Capuccino"}},
{ "order":{"id": "2",
"name": "Sofia",
"drink": "Late"
}}]