I'm trying to display a table based on JSON data. My JSON is formatted like this as spellData.json in my local directory:
[["Flash", 22722], ["Ignite", 5126], ["Heal", 4666], ["Smite", 3970], ["Teleport", 3892], ["Exhaust", 3118], ["Mark", 2495], ["Ghost", 571], ["Barrier", 459], ["Clarity", 239], ["Cleanse", 132], ["Clairvoyance", 10]]
I need to iterate through this data, and create a table that looks something like:
Spell : Occurrences
So far, index.html looks like this:
<html>
<head>
<link type="text/css" rel="stylesheet" href="css/common.css"/>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"> </script>
<script>
$(function() {
$.getJSON('spellData.json', function(data) {
var tr;
for (var i = 0; i < data.length; i++) {
tr = $('<tr/>');
tr.append("<td>" + data[i][0] + "</td>");
tr.append("<td>" + data[i][1] + "</td>");
$('table').append(tr);
}
});
});
</script>
</head>
<body>
<table>
<tr>
<th> Spell </th>
<th> Occurences </th>
</tr>
</table>
</body>
On my side, only "Spell Occurrences" show up, and not the json data.
Any help is appreciated! Thanks.
UPDATE: It seems like the code seems to work on other people's end.. But when I open index.html with a chrome, I only get "Spell Occurrences" and not the json data.
UPDATE: It seems like the problem was that Chrome doesn't support cross origin requests, so I can't do .getJSON with local files.
spellData.jsonis in the correct directory?scriptblock containing$.getJSONto after</table>, before</body>?console.log(data)at the beginning of the$.getJSONblock?