1 | <!DOCTYPE html> |
2 | <html lang="es"> |
3 | |
4 | <head> |
5 | |
6 | <meta charset="UTF-8"> |
7 | <meta name="viewport" content="width=device-width"> |
8 | |
9 | <title>Render en el cliente</title> |
10 | |
11 | </head> |
12 | |
13 | <body onload="descargaDatos()"> |
14 | |
15 | <h1>Render en el cliente</h1> |
16 | |
17 | <dl id="lista"> |
18 | <dt>Cargando…</dt> |
19 | <dd><progress max="100">Cargando…</progress></dd> |
20 | </dl> |
21 | |
22 | <script type="module"> |
23 | |
24 | import { exportaAHtml } from "./lib/js/exportaAHtml.js" |
25 | import { consumeJson } from "./lib/js/consumeJson.js" |
26 | import { htmlentities } from "./lib/js/htmlentities.js" |
27 | import { muestraError } from "./lib/js/muestraError.js" |
28 | |
29 | async function descargaDatos() { |
30 | try { |
31 | const respuesta = await consumeJson("srv/lista.php") |
32 | |
33 | let render = "" |
34 | for (const modelo of respuesta.body) { |
35 | |
36 | |
37 | |
38 | const nombre = |
39 | typeof modelo.nombre === "string" ? htmlentities(modelo.nombre) : "" |
40 | const color = |
41 | typeof modelo.color === "string" ? htmlentities(modelo.color) : "" |
42 | render += |
43 | `<dt>${nombre}</dt> |
44 | <dd>${color}</dd>` |
45 | } |
46 | lista.innerHTML = render |
47 | } catch (error) { |
48 | muestraError(error) |
49 | } |
50 | } |
51 | exportaAHtml(descargaDatos) |
52 | |
53 | </script> |
54 | |
55 | </body> |
56 | |
57 | </html> |