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

191
Visualizações
Ajax jQuery doesn't redirect to the url with Laravel

I'm new to Ajax, but I was able to make a form where I write data -> submit and the controller does it's job. My problem is that I wanted to make a delete button for the records, but it doesn't work, just reloads the page, the route is fine, the alert works fine and the token is fine too.

Here is the code:

The route

Route::post('/delete/{testTaker}', [TestTakerController::class, 'delete']);

The button

<form id="delete">
    {{ csrf_field() }}
       <button class="deletett" data-id="{{ $testTaker->testTaker }}">delete</button>
</form>

The js part:

<script src="http://code.jquery.com/jquery-3.3.1.min.js"
            integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
            crossorigin="anonymous">
</script>
<script>
        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
            }
        });
            $(".deletett").click(function(){
                var testTaker = $(this).data("id");
                alert(testTaker);
                jQuery.ajax({
                    url: "/delete/" + testTaker,
                    method: 'post',
                    data: {
                        name: testTaker
                    },
                    success: function(result){
                        jQuery('.alert').show();
                        jQuery('.alert').html(result.success);
                    }});
        });

    </script>
about 4 years ago · Juan Pablo Isaza
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