I am trying to create a very simple script using JQuery that will take a JSON dataset from a URL, filter the JSON using a hard-coded parameter and output the text from some of the data from the resulting filtered dataset. I would prefer to use JQuery, but am open to JavaScript options as well. This particular example is using the NYC CitiBike station status JSON feed and filtering using the "station_id" variable of 168 (the first station in the set).
I would also like this to refresh the query (or the div) every 30 seconds without refreshing the entire HTML page.
Below is an example of what I am attempting to accomplish. It should convey the general sense of what I am trying to accomplish.
<!DOCTYPE html>
<html lang="en">
<head>
<title>JavaScript - read JSON from URL</title>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
</head>
<body>
<div class="output"></div>
<script>
$.getJSON('https://gbfs.citibikenyc.com/gbfs/en/station_status.json', function(data) {
var objects = data.stations.filter(function(v){return v.station_id==168});
var text = `Station ID: ${objects.station_id}<br>
Bikes Available: ${objects.num_bikes_available}<br>
Docks Available: ${objects.num_docks_available}'
$(".output").html(text);
});
</script>
</body>
</html>