I'm creating a login form with html,css and javascript.
I'm doing a POST to an API in order to receive some JSON with the identified username that I just submitted in the form.
If the email and password are correct, I receive the JSON with all the info from my API. The problem is that I don't know how to manipulate the info that I receive... I'd like to save the JSON I'm receiving through the POST to a variable and then be able to access the account type or the other properties of that object.
<form name="login" id="myForm" action="API_URL" method="post" class="form-signin">
<h3 class="form-signin-heading">Por favor inicie sesión</h3>
<label for="inputEmail" class="sr-only">E-mail</label>
<input type="email" name="email" class="form-control" placeholder="E-mail" required autofocus>
<label for="inputPassword" class="sr-only">Password</label>
<input type="password" name="password" class="form-control" placeholder="Contraseña" required>
<div class="checkbox">
<label>
<input type="checkbox" value="remember-me"> Recordarme
</label>
</div>
<button class="btn btn-lg btn-primary btn-block" id type="submit">Iniciar sesión</button>
</form>
After hitting submit, I receive the JSON like this: !(https://i.stack.imgur.com/wM6aQ.jpg) This is my JQuery:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js%22%3E
$(document).ready(function() {
$('#myform').submit(function() {
$.ajax({
type: "POST",
url: '/form/',
data: {
email: $("#inputEmail").val(),
password: $("#inputPassword").val()
},
success: function(data)
{
if (data === 'Correct') {
var objeto = data.parse();
console.log(objeto);
}
else {
alert(data);
}
}
});
});
});
</script>
Can anyone please point me in the right direction?