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

346
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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