diff --git a/js/lib.main.js b/js/lib.main.js
index 2c30710..81403f2 100644
--- a/js/lib.main.js
+++ b/js/lib.main.js
@@ -132,16 +132,19 @@ async function getApi(path,auth = false) {
log(`getApi: Fetching from endpoint: ${url}, Auth=${auth}`)
try {
var resp = await fetch(url)
- if (resp != 200) {
+ var json = await resp.json()
+ log(`resp.status: ${resp.status}`)
+ log(`resp.json: ${json}`)
+ if (resp.status != 200) {
return false
}
if (!resp.ok) {
return false
}
- if (resp.json() === "[]") {
+ if (json === "[]") {
return 'empty'
}
- return resp.json();
+ return json;
} catch(err) {
return false
}
diff --git a/js/pis.js b/js/pis.js
index 918394d..8fa7a6f 100644
--- a/js/pis.js
+++ b/js/pis.js
@@ -32,18 +32,16 @@ async function insertData(json) {
Code |
Stations |
`
- div.insertAdjacentHTML("beforeend", tableHtml)
- const data = JSON.parse(json)
let results = 0
- for(var i = 0; i < data.length; i++) { // Break into separate function. Need to
+ for(var i = 0; i < json.length; i++) { // Break into separate function. Need to
// iterate over stops and print them in the
// format: `AVN, PRI, SHH... etc.`
- tableData += `${data[i][code]} |
- ${data[i][stops]} |
`
+ tableData += `${json[i]['code']} |
+ ${json[i]['stops']} |
`
results++
}
tableData += ""
- document.getElementById('result-table').insertAdjacentHTML("beforeend", tableData)
+ div.insertAdjacentHTML("beforeend", tableData)
document.getElementById('result-count').textContent = results
}
@@ -56,5 +54,6 @@ async function reset() {
document.getElementById('origin').value = ""
document.getElementById('destination').value = ""
document.getElementById('result-box').style = 'display:none'
+ document.getElementById('result-box').innerHTML = ''
document.getElementById('crs-box').style = 'display:block'
}
\ No newline at end of file