I am using the Untappd API to build a beer menu, and I have a question.
I want to display the JSON data that the server returns to me, and put it into a HTML table.
I have it working when I just create a list.json file and import it through my code, but whenever I try to use the URL itself, it does not pull the data. Can anyone help me figure this out?
The code below works by calling the local json file, but not with the URL.
json
"items": [
{
"id": xxx,
"section_id": xxx,
"position": x,
"untappd_id": xxx,
"label_image": "xxx",
"brewery_location": "xxx",
"abv": "xx",
"ibu": "xx",
"cask": xx
},
{
"id": xxx,
"section_id": xxx,
"position": x,
"untappd_id": xxx,
"label_image": "xxx",
"brewery_location": "xxx",
"abv": "xx",
"ibu": "xx",
"cask": xx
},
...
HTML/JS
<html>
<head>
<script src="https://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js">
</script>
<script>
$(function() {
var beer = [];
$.getJSON('test.json', function(data) {
$.each(data.items, function(i, f) {
var tblRow = "<tr>" + "<td>" + f.name + "</td>" +
"<td>" + f.brewery + "</td>" + "<td>" + f.ibu + "</td>" + "<td>" + f.abv + "</td>" + "</tr>"
$(tblRow).appendTo("#userdata tbody");
});
});
});
</script>
</head>
<body>
<div class="wrapper">
<div class="profile">
<table id="userdata" border="2">
<thead>
<th>Beer Name</th>
<th>Brewery</th>
<th>IBU</th>
<th>ABV</th>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</body>
</html>
Any help would be great!
jquery?