help with php and jquery function

0

Hello, I happen to have the following:

    $("#frmAcceso").on('submit',function(e)
{    
    e.preventDefault();
    logina=$("#logina").val();
    clavea=$("#clavea").val();

    if ((logina!="") && (clavea !=""))
    {                
         $.post("../Ajax/usuario.php?op=verificar",
            {"logina":logina,"clavea":clavea},
            function(data)
        {           
            alert(data.length);
            alert(data);

            if ((rpsta=="null") || (rpsta==null))
            {               
                //$(location).attr("href","Categoria.php"); 
                bootbox.alert("Usuario y/o Password incorrectos");           
            }
            else
            {
                //bootbox.alert("Usuario y/o Password incorrectos");
                $(location).attr("href","Categoria.php"); 
            }
        });
    }
    else
    {
        $("#logina").focus();
        swal('Oops...','Proporcione todos los datos','error');        
    }

})

and a php method that does the following

case 'verificar':

            $logina=$_POST['logina'];
            $clavea=$_POST['clavea'];

            $clavehash=hash("SHA256",$clavea);

            $rspta=$usuario->verificar($logina, $clavehash);            

            $fetch=$rspta->fetch_object();  


            if(isset($fetch))
                {                   
                    $_SESSION['idUsuario']=$fetch->idUsuario;                   
                    $_SESSION['Nombre']=$fetch->Nombre;
                    $_SESSION['Imagen']=$fetch->Imagen;
                    $_SESSION['Login']=$fetch->Login;
                }

            echo json_encode($fetch);
        break;

Now what the check function does is to see if the user is registered in the database.

public function verificar($login,$clave)
        {
            $sql="SELECT * FROM Usuario WHERE Login='$login' AND clave='$clave' AND Condicion='1'";                     
            return EjecutarConsulta($sql);
        }

Now the problem is that when valid if the query returns a data

if ((logina!="") && (clavea !=""))
    {                
         $.post("../Ajax/usuario.php?op=verificar",
            {"logina":logina,"clavea":clavea},
            function(data)
        {           
            alert(data.length);
            alert(data);

            if ((rpsta=="null") || (rpsta==null))
            {               
                //$(location).attr("href","Categoria.php"); 
                bootbox.alert("Usuario y/o Password incorrectos");           
            }
            else
            {
                //bootbox.alert("Usuario y/o Password incorrectos");
                $(location).attr("href","Categoria.php"); 
            }
        });
    }
    else
    {
        $("#logina").focus();
        swal('Oops...','Proporcione todos los datos','error');        
    }

Even if I return null, it directs me to the page of category.php

I commented that the page I have mounted on a server nas DS216J personal

Thanks a lot for the help

    
asked by Horacio Xochitemol 09.09.2017 в 08:03
source

1 answer

0

If you are returning rpsta from the php in json, you should pick up that variable from the previous data within the callback, but apparently what you return is not the rspta, but the values of < strong> $ fetch , leaving data with those values.

it would be something like:

 $.post("../Ajax/usuario.php?op=verificar",
            {"logina":logina,"clavea":clavea},
            function(data)
        {           
            alert(data.length);
            alert(data);

            if (data.length === 0 )
            {               
                //$(location).attr("href","Categoria.php"); 
                bootbox.alert("Usuario y/o Password incorrectos");           
            }
            else
            {//sesion exitosa}

or you can see if it dates in null

       $.post("../Ajax/usuario.php?op=verificar",
            {"logina":logina,"clavea":clavea},
            function(data)
        {           
            alert(data.length);
            alert(data);

            if (data)
            {               
                //sesion exitosa           
            }
            else
            {

                bootbox.alert("Usuario y/o Password incorrectos");
}
  

INSTALL THE DEVELOPER MOZILLA AND HELP WITH FIREBUG TO SEE THE   ANSWER AS IT IS AND THERE I KNOW HOW TO USE IT

    
answered by 09.09.2017 в 08:37