Advertisement
YavorJS

1.Bus Stop

Jul 28th, 2017
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Bus Stop</title>
  6. <style>
  7. #stopName {
  8. font-size: 1.5em;
  9. font-weight: 400;
  10. padding: 0.25em;
  11. background-color: aquamarine;
  12. }
  13. </style>
  14. <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
  15. </head>
  16. <body>
  17. <div id="stopInfo" style="width:20em">
  18. <div>
  19. <label for="stopId">Stop ID: </label>
  20. <input id="stopId" type="text">
  21. <input id="submit" type="button" value="Check" onclick="getInfo()"></div>
  22. <div id="result">
  23. <div id="stopName"></div>
  24. <ul id="buses"></ul>
  25. </div>
  26. </div>
  27. <script>
  28. function getInfo() {
  29. let bus=$('#stopId').val();
  30. let req={
  31. method: 'GET',
  32. url: `https://judgetests.firebaseio.com/businfo/${bus}.json`,
  33. success:displayBusStop,
  34. error:busError
  35. };
  36.  
  37. $.ajax(req);
  38.  
  39. function displayBusStop(req) {
  40. $('#buses').empty();
  41. let station=req.name;
  42. let buses=req.buses;
  43. $('#stopName').text(station);
  44.  
  45. for (let bus in buses) {
  46. let li =$('<li>');
  47. let text =`Bus ${bus} arrives in ${buses[bus]} minutes`;
  48. li.append(text);
  49. $('#buses').append(li);
  50. }
  51. }
  52.  
  53. function busError() {
  54. $('#buses').empty();
  55. $('#stopName').text('Error');
  56. }
  57. }
  58. </script>
  59. </body>
  60. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement