Update: to avoid the possibility that the problem comes solely down to the same origin policy, I've tried serving this locally where all assets are coming from http://localhost:4000
using Serve. It didn't solve the problem. So editing the fiddle might not work because of the same origin policy, but you can see the code there.
I'm trying to use Dynatable to load external JSON, skipping the read/normalize step (which generates the JSON from an existing table). This is supposed to be supported, but it's not working for me.
Here's my attempt on JSFiddle. Loading JSON from within the document (which doesn't seem terribly useful to me) is working perfectly, as seen in the fiddle. But pulling it in from a URL is not working at all.
Here's my JavaScript:
// getting JSON from the document works, but of what use is that?
$(document).ready( function() {
$('#local').dynatable({
dataset: {
records: JSON.parse($('#music').text())
}
});
// getting JSON from a remote source fails:
$('#remote').dynatable({
dataset: {
ajax: true,
ajaxOnLoad: true,
ajaxUrl: '//www.dynatable.com/dynatable-ajax.json',
records: []
}
});
});
...which refers to two tables, one with an id of "local" and another with an id of "remote", and to a script containing data for the local table:
<h3>Remote JSON: Failing</h3>
<table class="table table-striped" id="remote">
<thead>
<th>Some Attribute</th>
<th>Some Other Attribute</th>
</thead>
<tbody>
</tbody>
</table>
<hr>
<h3>Local JSON: Succeeding</h3>
<table class="table table-striped" id="local">
<thead>
<th style="color: black;">Band</th>
<th>Album</th>
</thead>
<tbody>
</tbody>
</table>
<script id="music">
[
{
"band": "The Police",
"album": "Ghost In The Machine"
},{
"band": "Supertramp",
"album": "Breakfast In America"
},{
"band": "Peter Tosh",
"album": "Mama Africa"
},{
"band": "The Police",
"album": "Regatta d'Blanc"
},{
"band": "The Police",
"album": "Zenyatta Mondatta"
},{
"band": "Supertramp",
"album": "Crime of the Century"
},{
"band": "Talking Heads",
"album": "Remain in Light"
},{
"band": "Talking Heads",
"album": "Speaking in Tongues"
}
]
</script>