Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var tbCarros = document.getElementById("tbCarros");
- var carros = {
- bindEvents : function () {
- window.addEventListener("load", carros.carregar);
- },
- carregar : function () {
- var url = "https://lit-tundra-68915.herokuapp.com/api/carros";
- fetch(url)
- .then((resp) => resp.json()) // Transform the data into json
- .then(function (data) {
- carros.exibir(data);
- })
- .catch (function (error) {
- alert("Erro no acesso ao Web Service ("+error+")");
- });
- },
- exibir : function (data) {
- for (car of data) {
- var linha = tbCarros.insertRow(-1);
- linha.insertCell(0).textContent = car.id;
- linha.insertCell(1).textContent = car.modelo;
- linha.insertCell(2).textContent = car.marca;
- linha.insertCell(3).textContent = car.ano;
- linha.insertCell(4).textContent = car.preco;
- }
- }
- }
- carros.carregar();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement