index.html 1.85 KB
Newer Older
Adrian's avatar
Adrian committed
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
29
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>.:: Sitio ::.</title>
  <link rel="stylesheet" href="./style.css">
  <script type="text/javascript">
    function login () { 
      document.getElementById('login').style.display = 'none';
      document.getElementById('data').style.display = 'block';
    }
    async function postData(url = '', data = {}) {
      const response = await fetch(url, {
        method: 'POST',
        mode: 'cors',
        cache: 'no-cache',
        credentials: 'same-origin',
        headers: {
          'Content-Type': 'application/json'
        },
        redirect: 'follow',
        referrerPolicy: 'no-referrer',
        body: JSON.stringify(data)
      });
      return await response.json();
    }
    function sendData () {
      postData('http://localhost:5000/send', { 
Adrian's avatar
Adrian committed
30
31
        titulo: document.querySelector('#title').value,
        text: document.querySelector('#description').value
Adrian's avatar
Adrian committed
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
      })
      .then((data) => {
        console.log(data);
      });
    }
  </script>
</head>
<body>
    <div class="main">
      <section id="login">
        <form action="#" onsubmit="event.preventDefault(); login();" class="login">
          <input type="text" required placeholder="Usuario">
          <input type="text" required placeholder="Contraseña">
          <button type="submit">ENVIAR</button>
        </form>
      </section>
      <section id="data">
          <form action="#" onsubmit="event.preventDefault(); sendData()" class="form">
            <input type="text" id="title" required placeholder="Titulo">
            <textarea name="comments" required  placeholder="Descripción" id="description" cols="30" rows="20"></textarea>
            <button type="submit">Enviar</button>
          </form>
      </section>
    </div>
</body>
</html>