mirror of
https://github.com/netbymatt/ws4kp.git
synced 2026-04-17 00:59:29 -07:00
remove ajax for json requests
This commit is contained in:
@@ -57,12 +57,7 @@ const navigation = (() => {
|
||||
const point = await utils.weather.getPoint(latLon.lat, latLon.lon);
|
||||
|
||||
// get stations
|
||||
const stationsResponse = await fetch(point.properties.observationStations, {
|
||||
method: 'GET',
|
||||
mode: 'cors',
|
||||
type: 'GET',
|
||||
});
|
||||
const stations = await stationsResponse.json();
|
||||
const stations = utils.fetch.json(point.properties.observationStations);
|
||||
|
||||
const StationId = stations.features[0].properties.stationIdentifier;
|
||||
|
||||
|
||||
@@ -182,6 +182,18 @@ const utils = (() => {
|
||||
return url;
|
||||
};
|
||||
|
||||
// ********************************* fetch ********************************************
|
||||
const json = async (url) => {
|
||||
const response = await fetch(url, {
|
||||
method: 'GET',
|
||||
mode: 'cors',
|
||||
type: 'GET',
|
||||
});
|
||||
|
||||
if (!response.ok) throw new Error(`Fetch error ${response.status} ${response.statusText} while fetching ${url}`);
|
||||
return await response.json();
|
||||
};
|
||||
|
||||
// return an orderly object
|
||||
return {
|
||||
image: {
|
||||
@@ -219,6 +231,9 @@ const utils = (() => {
|
||||
cors: {
|
||||
rewriteUrl,
|
||||
},
|
||||
fetch: {
|
||||
json,
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user