Login with Ajax and PHP with redirection

Asked

Viewed 419 times

0

Hello, I am trying to log in, but I am coming across the following, when you login redirects to the same div of the page, instead of going straight to another page. Someone has a solution?

HTML

 <div class="loader" style="display: none;"><img src="assets/img/loader.gif" alt="Carregando" /></div>
            <div class="mensagem-erro"></div>



        <form action="logar.php" class="form-signin" method="post" id="frmLogin">
            <p class="text-muted text-center btn-block btn btn-primary btn-rect">
               Digite seu usuário e senha


            </p>
            <input name="username"type="text" placeholder="Usuário" class="form-control" />
            <input name="password" type="password" placeholder="Senha" class="form-control" />
            <button class="btn text-muted text-center btn-danger" id="btn-login" type="submit">Entrar</button>
        </form>
    </div>

AJAX

$(function($) {

    $('#frmLogin').submit(function() {

        // Limpando mensagem de erro
        $('div.mensagem-erro').html('');

        // Mostrando loader
        $('div.loader').show();

        // Enviando informações do formulário via AJAX
        $(this).ajaxSubmit(function(resposta) {

            // Se não retornado nenhum erro
            if (!resposta)
                // Redirecionando para o painel
                window.location.href = 'logar.php';
            else
            {
                // Escondendo loader
                $('div.loader').hide();

                // Exibimos a mensagem de erro
                $('div.mensagem-erro').html(resposta);
            }

        });

        // Retornando false para que o formulário não envie as informações da forma convencional
        return false;

    });
});
  • Which PHP code, Html. Returns some error ?

  • edited and placed :)

  • !answer = false if its value is true. This is the intention ?

  • I think the best way to solve this error would be to redirect by Ajax code instead of PHP right? But I don’t know how to do this

  • Post the PHP code, so we can help.

  • Friend, the code in PHP is just a common login does not influence anything in Ajax

  • You have to see the redirect in the log.php file, because the error is not in html or ajax.

  • Redirect in php file is ok, I redirect with header, usually

Show 3 more comments
No answers

Browser other questions tagged

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