Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

345
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda