I've seen a couple posts on this but I haven't been able to make anything work. I'm trying to pull the data from a JSON file into an HTML table. Each post I've tried to follow to make it work brings back nothing so I don't know if the functions are working and I'm just not pulling them in right, or if they're all just wrong. So, here's my JSON file:
{
"Parts": [
{
"CIMs":17748,
"Name":"Bizerba XC100 Printer",
"Description":"Bizerba XC100 Print Assembly",
"Category":"Scales",
"Location": "Shelf 1",
"Amount": 3
},
{
"CIMs":17738,
"Name": "Bizerba XC100 Spool",
"Description":"Bizerba XC100 Label Spool",
"Category":"Scales",
"Location": "Shelf 1",
"Amount":4
},
{
"CIMs":12345,
"Name":"Lexmark MS711de",
"Description": "Lexmark MS711de for FMC and ICC",
"Category":"Printers",
"Location":"Crash Site",
"Amount":1
},
{
"CIMs":23456,
"Name":"Bill Acceptor",
"Description":"Bill Acceptor for SCO 4.2 and 5.0",
"Category":"SCO",
"Location":"Shelf 2",
"Amount":4
},
{
"CIMs":34567,
"Name": "TCU",
"Description":"TCU for nextgen registers",
"Category":"Registers",
"Location":"Shelf 2",
"Amount":2
},
{
"CIMs":45678,
"Name":"HP Desktop",
"Description":"HP Desktop for use by everyone but managers",
"Category":"Computers",
"Locaton":"Shelf 2",
"Amount":2
},
{
"CIMs":56789,
"Name":"HP DL160 HDD",
"Description":"HP DL160 G6 160GB 2.5 inch replacement drive",
"Category":"Servers",
"Location":"Shelf2",
"Amount":6
}
]}
And here's the script I have setup:
<script>
$(function(){
var partsList = [];
$.getJSON('partslist.json', function(json){
$.each(json.properties, function(i, f) {
var tblRow = "<tr>" + "<td>" + f.CIMs + "</td>"
+ "<td>" + f.Name + "</td>"
+ "<td>" + f.Description + "</td>"
+ "<td>" + f.Category + "</td>"
+ "<td>" + f.Location + "</td>"
+ "<td>" + f.Amount + "</td>" + "</tr>";
$(tblRow).appendTo("#partsListData tbody");
});
});
}); </script>
My table:
<section>
<h2>Parts</h2>
<table id="partsListData" border="1">
<thead>
<th>CIMs</th>
<th>Name</th>
<th>Description</th>
<th>Category</th>
<th>Location</th>
<th>Amount</th>
</thead>
<tbody>
</tbody>
</table>
<p><a href="#" style="color: black; align-content: center;">Add Parts</a></p>
<p><a href="#" style="color: black; align-content: center;">List Categories</a></p>
</section>
What am I missing? What do I need to do in my webpage to make that pull? I've tried placing the script right under the tag and also within the with no luck. Help?
EDIT: I managed to get the table to show up with the headers but the data comes back undefined. I have also updated the code in the post to what I currently have.