Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

190
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!