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

292
Views
405 (Method Not Allowed) on post method laravel ajax

I get an 405 (Method Not Allowed) error when sending an AJAX request. I've been working hard looking for a solution but still receive the same error.

I have added this inside the header section:

<meta name="csrf-token" content="{{ csrf_token() }}">

And this is the AJAX code:

function AjaxCall() {
  var token = $('meta[name="csrf-token"]').attr('content');
  
  $.ajax({
    url: 'insertNum',
    type: 'POST',
    dataType: 'json',
    header: {
      'X-CSRF-TOKEN': token
    },
    data: {
      _token: token,
      _method: "PUT",
    },
    success: function() {
      console.log('success');
    }
  });
}

Laravel code:

try {
  $lastNum = DB::table('no_antrian')->select('antrian')->first();

  if (!is_null($lastNum)) 
  {    
    $data = DB::table('no_antrian')->update(['antrian' => $lastNum + 1]);
  }

  return response()->json(['success' => 'Sukses']);
}
catch(\Exception $e) {
  return response()->json(['error' => 'failed']);
}

Route:

Route::post('antrian/insertNum', [AntrianController::class, 'getQueueNum']);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

please Remove put method inside data

 var token = $('meta[name="csrf-token"]').attr('content');
 let myData = $('form').find('input[name="my_data"]').val();
  
  $.ajax({
    url: 'insertNum',
    type: 'POST',
    dataType: 'json',
    data: {
      _token: token,
       my_data: myData
    },
    success: function() {
      console.log('success');
    }
  });
about 4 years ago · Juan Pablo Isaza Report
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!