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

142
Views
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 answers
Answer question

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