H. 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 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 { muestraError } from "./lib/js/muestraError.js"
22 import { enviaJson } from "./lib/js/enviaJson.js"
23
24 async function envia() {
25 try {
26 const datos = {
27 saludo: "Hola",
28 nombre: "pp"
29 }
30 const respuesta =
31 await enviaJson(
32 "srv/json.php", datos)
33 alert(respuesta.body)
34 } catch (error) {
35 muestraError(error)
36 }
37 }
38 // Permite que los eventos de html usen la función.
39 window["envia"] = envia
40
41 </script>
42
43</body>
44
45</html>
skip_previous skip_next