K. index.html

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>Servicio que devuelve un resultado</title>
10
11</head>
12
13<body>
14
15 <h1>Servicio que devuelve un resultado</h1>
16
17 <p><button onclick="resultado()">Resultado</button></p>
18
19 <script type="module">
20
21 import { invocaServicio } from "./lib/js/invocaServicio.js"
22 import { muestraError } from "./lib/js/muestraError.js"
23
24 async function resultado() {
25 try {
26 const respuesta =
27 await invocaServicio(
28 "srv/devuelve.php")
29 const body = respuesta.body
30 alert(`Nombre: ${body.nombre}
31Mensaje: ${body.mensaje}`)
32 } catch (error) {
33 muestraError(error)
34 }
35 }
36 // Permite que los eventos de html usen la función.
37 window["resultado"] = resultado
38
39 </script>
40
41</body>
42
43</html>
skip_previous skip_next