Does not enter the ajax block

Asked

Viewed 26 times

0

Good Morning!

I have the following code:

<?php
   $titulo = "Site";
?>
<html>
    <head>
      <title><?php echo $titulo; ?></title>
      <link rel="shortcut icon" href="_imgs/favicon.ico">    
      <script type="text/javascript" src="_scripts/_js/jquery-2.1.4.min.js"></script>
      <link type="text/css" rel="stylesheet" href="_css/estilo.css" />    
    </head>
    <body>

    <div class="corpo">

      <div class="cabecalho">
          <h2 id="tituloCabecalho"> Bem Vindo ao Portal do Cliente <a href="index.php"><?php echo $titulo; ?></a> </h2>
      </div>

      <div id="formLogin" class="login">
        <form action="" method="post" >
         <label>Entrar</label> <br /> <br />
         <input type="email" name="email" id="email" class="email" placeholder="E-mail" class="camposForm" required /> <br /> <br />
         <input type="password" name="senha" id="senha" class="senha" placeholder="Senha" class="camposForm" required /> <br /> <br />
         <input type="checkbox" name="lembrar" id="lembrar" class="lembrar" /> <label id="lembrarLabel">Lembrar-me</label>  <br /> <br />
         <div class="entrarRecuperar">         
           <div class="entrarDiv"><button id="entrar" class="btnEntrar">Entrar</button></div>
           <div class="recuperarDiv"><a href="recuperaSenha.php">Esqueceu sua senha?</a></div>
         </div>
         <div class="clear"></div>
         <div id="erroLogin"></div>
        </form>     
      </div><br>

      <div class="cadastro">Registro</div>

    </div>
</body>
</html>

<script>
    $('#entrar').click(function () {
        email = $('#email').val();
        senha = $('#senha').val();
        if (email=="") {
            alert("Preencha E-mail");
            return false;
        }
        if (senha=="") {
            alert("Preencha Senha");
            return false;
        }

        $.ajax({
             type: "POST",
             url: "_requeridos/sessaoLogin.php",
             data: {email: email, senha: senha},
             dataType: 'json'
            }).done(function(resposta){
              alert();
              if (resposta == "ERRO") {
                  $("#erroLogin").html("Erro de Login");              
              } else {
                  window.location="oi.html";
              }
        });

        return false;
    });
</script>

The js $.ajax({ above is not able to find form field values.

What’s wrong with that code?

Actually not even getting into Ajax is.

  • I never used this type of formwork for the Ajax block, usually I would use an attribute success receiving a function (data) in the ajax object itself ( below datatype).. Test this and see if it works. And another, the server is receiving and treating the request correctly? Ever tried using a life Postman?

  • Have you tried to capture the fail request to check if it failed?

  • I found the error: it was that in php I was printing straight without using json_encode function. Thank you

  • Can anyone explain what returns in . done? If it is the same thing that is in succession and faillure?

  • The done will match using the success with some small details of different implementation. The server is receiving the request or not ? Any error appears in the browser ? or the server ?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.