I have this problem, I am doing a login and a register but when I try to verify if the data is being sent through a alert();
the information is not being sent.
Code
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<title>RegisterPrueba</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<form class="guardar" method="POST">
<input type="text" id="Nombre" placeholder="Nombre">
<input type="password" id="password" placeholder="Contraseña">
<input type="submit" id="Guardar">
</form>
</body>
</html>
<script type="text/javascript">
$(document).ready(function() {
$('#Guardar').click(function() {
var datos = $('#guardar').serialize();
alert(datos);
return false;
$.ajax({
type: "POST",
url: "guardar.php",
data: datos,
success: function() {
}
});
});
});
</script>
Apart from the problem with the ID that other users tell you, the method
serialize()
takes the values of the fields using theirname
. Your fields have no attributename
. Add it to it and it will work for you (you will also have to add the id to the form):I would recommend putting this code in the submit event of the form
HTML elements or even tags can be accessed through JS through their id or class; as follows
Namely:
For your exercise, I would change the class to an id, so that your exercise looks like this