-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
28 lines (25 loc) · 884 Bytes
/
script.js
File metadata and controls
28 lines (25 loc) · 884 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// URL de la API
const apiUrl = 'https://jsonplaceholder.typicode.com/posts';
// Elementos del DOM
const statusElement = document.getElementById('status');
const tableBody = document.getElementById('posts-table');
// Función para obtener los datos de la API
fetch(apiUrl)
.then(response => response.json())
.then(data => {
// Limpiar mensaje de estado
statusElement.textContent = '';
// Generar filas de la tabla dinámicamente
data.forEach(post => {
const row = document.createElement('tr');
row.innerHTML = `
<td>${post.id}</td>
<td>${post.title}</td>
`;
tableBody.appendChild(row);
});
})
.catch(error => {
console.error('Error al obtener los datos:', error);
statusElement.textContent = 'Error al cargar los datos';
});