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

148
Visualizações
Unable to get the the data from AJAX request to Laravel controller and work with it?

I am making the following AJAX call:

var dataURL = canvas.toDataURL();
var token = "{{ csrf_token() }}";

$.ajax({
      type: "POST",
      url: "{{route('site.image.store')}}",
      data: {
        imgBase64: dataURL,
      },
      processData: false,
      contentType: false,
      headers: {'X-CSRF-TOKEN': token},
    }).done(function(response) {
      console.log('done');
});

And my controller is:

public function store(Request $request)
{
    dd($request->all());
}

However I am getting and empty array []. How can I access the imgBase64 data and work with it in the controller?

I am not submitting a form to make the post request I am just using the canvas data.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

The reason it does not work for you is that Laravel uses the Content-Type header of the request to determine how to parse the input data.

If you specify contentType: false in your request, you're specifically building the AJAX request in such a way that no Content-Type header will be sent.

That way Laravel does not know how to parse the body of the request.

So to resolve your issue you have to specify the correct contentType for your request. The default for jQuery's $.ajax() function is application/x-www-form-urlencoded; charset=UTF-8 (see documentation)

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