Advertisement
didkoslawow

Untitled

Jun 22nd, 2023
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. async function getInfo() {
  2.    const baseUrl = 'http://localhost:3030/jsonstore/bus/businfo/';
  3.    const input = document.getElementById('stopId');
  4.    const result = document.getElementById('stopName');
  5.    const buses = document.getElementById('buses');
  6.  
  7.    const busStop = input.value;
  8.  
  9.    buses.innerHTML = '';
  10.    input.value = '';
  11.  
  12.    try {
  13.      const response = await fetch(baseUrl + busStop);
  14.      const data = await response.json();
  15.  
  16.      result.textContent = data.name;
  17.  
  18.      for (const busId in data.buses) {
  19.        const li = document.createElement('li');
  20.        const time = data.buses[busId];
  21.  
  22.        li.textContent = `Bus ${busId} arrives in ${time} minutes`;
  23.        buses.appendChild(li);
  24.      }
  25.    } catch (error) {
  26.      result.textContent = 'Error';
  27.    }
  28.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement