Here’s what I’m trying to do: NOAA offers data from public datasets on all kinds of climate data. What I am trying to do, in a javascript-only solution, is download the station and station metadata files from NOAA (plain text positional files), parse the metadata file for weather stations with the data I want (precipitation, daily max temps, min temps, and mean temps. From those data I can download the weather data from a station, and plot it using Plotly.
I’ve tried many different methods with xhttp, but I always end up in the same place. This is typical of my efforts:
<script>
xhttpStation.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
stationData = xhttpStation.responseText;
};
xhttpStation.open("GET", "https://www.ncei.noaa.gov/pub/data/ghcn/daily/ghcnd-stations.txt", false);
xhttpStation.send();
</script>
I can’t find a way to get from the .responseText to back outside the function and on my way with the data to make the dropdown select lists of the station ids. I have to be missing something, because the asynchronous nature of the xhttp call allows my code to fly on by without wating to get the data.