Adjust PIS Code
This commit is contained in:
parent
d54098562d
commit
cd3a4dad33
@ -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
|
||||
}
|
||||
|
11
js/pis.js
11
js/pis.js
@ -32,18 +32,16 @@ async function insertData(json) {
|
||||
<th class="code">Code</th>
|
||||
<th class="stops">Stations</th>
|
||||
</tr>`
|
||||
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 += `<tr><td class="code">${data[i][code]}</td>
|
||||
<td class="stops">${data[i][stops]}</td></tr>`
|
||||
tableData += `<tr><td class="code">${json[i]['code']}</td>
|
||||
<td class="stops">${json[i]['stops']}</td></tr>`
|
||||
results++
|
||||
}
|
||||
tableData += "</table>"
|
||||
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'
|
||||
}
|
Reference in New Issue
Block a user