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

340
Views
Laravel: Ajax using problem always return error 500

Good day. Trying to send GET method using Ajax and always getting error 500. CSRF used but I can't find where is error. This is my code:

blade

.....
<meta name="csrf-token" content="{{ csrf_token() }}">
.....
    <script>
        document.addEventListener("DOMContentLoaded", function() {
            let infoModal = document.getElementById('Modal_UserEdit');
            infoModal.addEventListener('show.bs.modal', function () {
                let userId = document.getElementById("_Input_UserID").value;

                $.ajaxSetup({
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                    }
                });

                $.ajax({
                    url: "{{ route('settings.user.show') }}",
                    type: 'GET',
                    data: { '_token': '{{ csrf_token() }}', id: userId },
                    success: function(data) {

                        console.log(data);

                    }
                });
            });
        });
    </script>

web.php

Route::get('settings/users/user/show', [UserController::class, 'show'])->name('settings.user.show');

UserController.php

    public function show(Request $request)
    {
        $form = $request->only(['id']);
        $user = DB::table('users')->where('id', $form['id'])->first()->toJson();
        return $user;
    }

Don't think this is CSRF problem, because:

  1. If inside UserController just ask something like dd($form) it returns
  2. If disable CSRF in Kernal.php - nothing changed...

Somebody please help to understand what I'm doing wrong? Thank you!

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Fixed. Thank for log reminder )))

Fixed code:

    public function show(Request $request)
    {
        $form = $request->only(['id']);
        $user = DB::table('users')->where('id', $form['id'])->first();
        return json_encode($user);
    }

over 4 years ago · Santiago Trujillo 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!