I try to send the information of a form, to a database, so before sending it, I want to check that all the fields that I have marked with "required" are filled in.
For this I am trying the following:
$("#comprobarDatos").on("click", function(e){
if(!valid) {
e.preventDefault();
} else {
$.ajax({
type: 'POST',
url: 'php/enviar_pedido.php',
data: {'referencia': referencia,
'detalles': detallesCi,
'tipo': tipoCi,
...etc
}
})
.done(function(){
alert('Pedido enviado con éxito');
})
.fail(function(){
alert("Error 01");
})
})
This is the INPUT:
<input type="submit" id="comprobarDatos" value="Comprobar Pedido">
If it validates that the fields are in required. However, it does not execute anything from the AJAX.
Thank you.