Spara URL (json) som fil och visa ut
<?php
$outfile= 'result.json';
$url='http://online.equipe.com/api/v1/class_sections/22570/results.json';
$json = file_get_contents($url);
if (file_exists($outfile) && (filemtime($outfile) > (time() - 60 * 5 ))) {
// Cache file is less than five minutes old.
// Don't bother refreshing, just use the file as-is.
$json = file_get_contents($url);
echo "Using cached file!";
} else {
if($json) {
if(file_put_contents($outfile, $json)) {
echo "Saved JSON fetched from “{$url}” as “{$outfile}”.";
}
else {
echo "Unable to save JSON to “{$outfile}”.";
}
}
else {
echo "Unable to fetch JSON from “{$url}”.";
}
}
?>
<div id="myTable" style="margin-top:20px";></div>
<script type="text/javascript">
jQuery(function(){
jQuery.getJSON("../result.json", function(result){
// Gets file and lets me use the content of the jsonArray
//alert(result[0].rider_name)
for (var i = 0; i < result.length; i++) // Loop through the jsonArray
{
document.getElementById("myTable").innerHTML += "<ul><li>"+result[i].rider_id+"</li></ul>";
}
});
});
</script>