Frontend: Add API Call for find-code
Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
parent
eb828896d0
commit
908ded08a7
@ -27,7 +27,7 @@ async function parseData(values){
|
|||||||
getData("tiploc", values.tiploc)
|
getData("tiploc", values.tiploc)
|
||||||
} else if (values.stanox != ""){
|
} else if (values.stanox != ""){
|
||||||
getData("stanox", values.stanox)
|
getData("stanox", values.stanox)
|
||||||
} else if (values.station != ""){
|
} else if (values.name != ""){
|
||||||
getData("name", values.name)
|
getData("name", values.name)
|
||||||
} else {
|
} else {
|
||||||
errorNoData()
|
errorNoData()
|
||||||
@ -36,8 +36,22 @@ async function parseData(values){
|
|||||||
|
|
||||||
async function getData(type, value){
|
async function getData(type, value){
|
||||||
console.log(`Looking for: ${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(){
|
async function errorNoData(){
|
||||||
|
console.log("No data entered")
|
||||||
window.alert("You haven't entered any data")
|
window.alert("You haven't entered any data")
|
||||||
|
}
|
||||||
|
|
||||||
|
async function errorFetch(err){
|
||||||
|
console.log("Error fetching data")
|
||||||
|
console.log(err)
|
||||||
}
|
}
|
Reference in New Issue
Block a user