Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

88
Visualizações
Jquery Ajax POST method using GET instead of POST?

Ok so i have this html login page for a test website:

<body>
    <div class = "container-login">
        <form class ="devbook-form" id ="login">
            <span>
                Welcome to Devbook!
            </span>
            <div>
                <input type="text" name="email" id="email" placeholder="email" required="required">
            </div>
            <div> 
                <input type="password" name="password" id="password" placeholder="password" required="required">
            </div>
            <a href="/register">Register Here</a>
            <button type="submit" class="btn-devbook">Login</button>
        </form>
    </div>
    <script src="/assets/js/jquery.min.js" ></script>
    <script src="/assets/js/login.js"></script>
</body>
</html>

The scripts calls for the js responsible for communication with an API, but it simply doesnt start the Ajax, or the Ajax is working in the wrong way, but must probably it doesnt start the Ajax cause i tried to put a console.log("Testing") in the button but the consoles gives nothing. I have another ajax button for another html page which works perfectly, why is that?

This is the Ajax Jquery i'm using to get the form for a login button:

$('#login').on('submit', loginAccount);

function loginAccount(event){
    event.PreventDefault();

    $.ajax({
        url:"/login",
        method:"POST",
        data: {
            email: $('#email').val(),
            password: $('#password').val(),
        }
    }).done(function() {
        window.location = "/home";
    }).fail(function() {
        alert("Invalid email or password");
    });
}

All this is meant to communicate with an API working on localhost:3000, which was made with Golang using GIN framework, it has an public.POST("/login", controllers.LoginAccount) which is meant to communicate with another API. The html page, jquery ajax and register golang function all works, but the login it doesnt, it always performs a GET instead of a POST, why is that?

over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda