Pantalla de login con llamada a api
Publicado por Marta (3 intervenciones) el 11/05/2021 08:53:35
Buenos días. Necesito hacer una pantalla de Login con email y contraseña que cuando pulse al boton de validar/acceso me devuelva un token cuando llamo a un api. Tengo este código, no sé que me falla, he estado viendo tutoriales y no acabo de entenderlo, a ver si alguien puede echarme una mano. Un saludo.
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<!DOCTYPE html>
<html>
<title> FORMULARIO ACCESO COUNCILBOX </title>
<body>
<h1>LOGIN</h1>
<form id="formulario" name="formulario" method="POST">
<div>
<label>
<p>Email</p>
<input type="text" id="email" name="email" placeholder="email" />
</label>
<label>
<p>Password</p>
<input type="password" id="password" name="password" placeholder="password" />
</label>
<button type="submit" onclick="Login()">Login</button>
</div>
</form>
</body>
<script>
function Login(){
let form = document.forms["formulario"];
let fd = new FormData(form);
let data = {};
for (let [key, prop] of fd) {
data[key] = prop;
}
VALUE = JSON.stringify(data, null, 2);
console.log(VALUE);
const url= "https://www.getpostman.com/collections/dc3a2b2ce35f95d6eab5";
const myHeaders = new Headers();
myHeaders.append('Content-Type', 'application/json');
fetch()(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: VALUE,
})
.then(data => data.json())
.then(data => { console.log(data) })
.catch((err) => {
console.error(err);
})
}
</script>
</html>
Valora esta pregunta


0