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

117
Views
Illegal invocation while sending formdata to PHP server using ajax

When I execute the code I keep getting this error:

Uncaught TypeError: Illegal invocation

How do I fix this?

const formdata = new FormData();
for (const file of myfile.files) {
  formdata.append("myFiles[]", file);
}

$.ajax({
  url: '/all_backend_stuff/server.php',
  type: 'POST',
  data: {
    "file": formdata
  },
  success: function(response) {
    alert(response);
  },
  complete: function() {}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<input type="file" id="myfile" name="myFiles[]" accept=".pdf,.jpg,.png">

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

When sending FormData in a jQuery AJAX request you need to supply the object directly to the data property (not as the value of a property within an object).

In addition you need to set both contentType and processData to false:

$.ajax({
  url: '/all_backend_stuff/server.php',
  type: 'POST',
  data: formdata,
  contentType: false,
  processData: false,
  success: function(response) {
    alert(response);
  },
  complete: function() {}
});
about 4 years ago · Juan Pablo Isaza 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!