I am trying to send my form and according to the response of my php file. Do something in my ajax.
(Use the function) echo json_encode ($ data);
But, never enter the true.
This is how I send my form.
$(document).on('ready',function(){
$('#btsave').click(function(){
if(validar()){ // si la validacion es correcta. Se envia el formulario
var url = "registro.php";
$.ajax({
type: "POST",
url: url,
data: $("#formulario").serialize(),
dataType:"JSON",
success: function(data)
{
if(data.message){
alert("Soy True");
//
}else{
alert("Soy false");
//hacer segun
}
}
});
}
});
});
this is my php file. In this way I make a query, and according to the answer. I want to do something.
if($resultado->fetchColumn()>0){
//echo "El correo ".$correo." Ya se encuentra registrado. <a href='olvidepas.php'> ¿olvidaste tu contraseña?</a<";
$data["message"]=false;
}else{
$query = "INSERT INTO 'usuarios'('correo', 'pass') VALUES (:fname,:lname)";
$pdoResult = $base->prepare($query);
$pdoExec = $pdoResult->execute(array(":fname"=>$correo,":lname"=>$pass));
echo "Éxito";
$data["message"]=true;
}
echo json_encode($data);
** acts strangely, since it never enters the true. Only in the false, because when I send a form. And I give send. My button does not say anything to me. and when I put it back send. It already tells me the false alert. (And if it says false it's already registered.) **