Advertisement
Guest User

Untitled

a guest
Jul 21st, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. var tbCarros = document.getElementById("tbCarros");
  2.  
  3. var carros = {
  4. bindEvents : function () {
  5. window.addEventListener("load", carros.carregar);
  6. },
  7. carregar : function () {
  8. var url = "https://lit-tundra-68915.herokuapp.com/api/carros";
  9. fetch(url)
  10. .then((resp) => resp.json()) // Transform the data into json
  11. .then(function (data) {
  12. carros.exibir(data);
  13. })
  14. .catch (function (error) {
  15. alert("Erro no acesso ao Web Service ("+error+")");
  16. });
  17. },
  18. exibir : function (data) {
  19. for (car of data) {
  20. var linha = tbCarros.insertRow(-1);
  21.  
  22. linha.insertCell(0).textContent = car.id;
  23. linha.insertCell(1).textContent = car.modelo;
  24. linha.insertCell(2).textContent = car.marca;
  25. linha.insertCell(3).textContent = car.ano;
  26. linha.insertCell(4).textContent = car.preco;
  27. }
  28. }
  29. }
  30.  
  31. carros.carregar();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement