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

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

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 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