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

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

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