diff --git a/static/js/find-code.js b/static/js/find-code.js index dff065d..524193f 100644 --- a/static/js/find-code.js +++ b/static/js/find-code.js @@ -27,7 +27,7 @@ async function parseData(values){ getData("tiploc", values.tiploc) } else if (values.stanox != ""){ getData("stanox", values.stanox) - } else if (values.station != ""){ + } else if (values.name != ""){ getData("name", values.name) } else { errorNoData() @@ -36,8 +36,22 @@ async function parseData(values){ async function getData(type, value){ console.log(`Looking for: ${type} ${value}`) + try { + var url = `${window.location.origin}/api/v1/${type}/${value}`; + var resp = await fetch(url); + console.log(`Response: ${resp.json}`) + return await resp.json() + } catch (err) { + errorFetch(err) + } } async function errorNoData(){ + console.log("No data entered") window.alert("You haven't entered any data") +} + +async function errorFetch(err){ + console.log("Error fetching data") + console.log(err) } \ No newline at end of file