Skip to content

Instantly share code, notes, and snippets.

@butlermh
Last active December 27, 2015 03:39
Show Gist options
  • Save butlermh/7260966 to your computer and use it in GitHub Desktop.
Save butlermh/7260966 to your computer and use it in GitHub Desktop.
Using YUI to display data.taipei.gov.tw dataset
<!DOCTYPE html>
<title>Displaying a remote JSON DataSource in a DataTable</title>
<body class="yui3-skin-sam">
<div id="datatable"></div>
<script src="http://yui.yahooapis.com/3.5.0/build/yui/yui-min.js"></script>
<script>
YUI().use('datatable', 'datasource-get', 'datasource-io', 'datasource-jsonschema', function (Y) {
var src = new Y.DataSource.Get({
source: 'http://data.taipei.gov.tw/opendata/apply/json/NzRBNTc0NDUtMjMxMi00RTk1LTkxMjgtNzgzMzU5MEQzRDc3'
});
src.plug(Y.Plugin.DataSourceJSONSchema, {
schema: {
resultListLocator: 'results.json.json',
resultFields: [
'name',
'district'
]
}
});
var table = new Y.DataTable({ columns: [
'name',
'district'
]
});
table.plug(Y.Plugin.DataTableDataSource, { datasource: src });
table.render('#datatable');
table.datasource.load({ request: '?per_page=10' });
});
</script>
</body>
@xbddc
Copy link

xbddc commented Nov 1, 2013

Hi Mark,

I have looked into this issue, and here is the patch might work:

@@ -6,11 +6,11 @@
 <script>
     YUI().use('datatable', 'datasource-get', 'datasource-io', 'datasource-jsonschema', function (Y) {
         var src = new Y.DataSource.Get({
-            source: 'http://data.taipei.gov.tw/opendata/apply/json/NzRBNTc0NDUtMjMxMi00RTk1LTkxMjgtNzgzMzU5MEQzRDc3'
+            source: 'redir.php?u=data.taipei.gov.tw/opendata/apply/json/NzRBNTc0NDUtMjMxMi00RTk1LTkxMjgtNzgzMzU5MEQzRDc3'
         });
         src.plug(Y.Plugin.DataSourceJSONSchema, {
             schema: {
-            resultListLocator: 'results.json.json',
+            resultListLocator: '',
             resultFields: [
                 'name',
                 'district'

In redir.php:

<?php
$url = $_GET['u'];
$callback = $_GET['callback'];
$fs = fopen('http://'.$url, 'r');

header("Content-Type: application/javascript");
echo $callback.'(';
  fpassthru($fs);
echo ');';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment