| 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 recibe y devuelve JSON</title> | 
  | 10 |  | 
  | 11 | </head> | 
  | 12 |  | 
  | 13 | <body> | 
  | 14 |  | 
  | 15 |  <h1>Servicio que recibe y devuelve JSON</h1> | 
  | 16 |  | 
  | 17 |  <p><button onclick="envia()">Envía JSON</button></p> | 
  | 18 |  | 
  | 19 |  <script type="module"> | 
  | 20 |  | 
  | 21 |   import { exportaAHtml } from "./lib/js/exportaAHtml.js" | 
  | 22 |   import { muestraError } from "./lib/js/muestraError.js" | 
  | 23 |   import { enviaJson } from "./lib/js/enviaJson.js" | 
  | 24 |  | 
  | 25 |   async function envia() { | 
  | 26 |    try { | 
  | 27 |     const datos = { | 
  | 28 |      saludo: "Hola", | 
  | 29 |      nombre: "pp" | 
  | 30 |     } | 
  | 31 |     const respuesta = | 
  | 32 |      await enviaJson( | 
  | 33 |       "srv/json.php", datos) | 
  | 34 |     alert(respuesta.body) | 
  | 35 |    } catch (error) { | 
  | 36 |     muestraError(error) | 
  | 37 |    } | 
  | 38 |   } | 
  | 39 |   exportaAHtml(envia) | 
  | 40 |  | 
  | 41 |  </script> | 
  | 42 |  | 
  | 43 | </body> | 
  | 44 |  | 
  | 45 | </html> |