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

181
Visualizações
Is there any way to send a file trough an array via AJAX?

I filled up an array with a lot of information(80+variables) and 1 file.

var ArrayEnv= {LOTS OF VARIABLES DECLARED + 1 File}
console.log(ArrayEnv); -> Just for testing purposes

$.ajax({
   url: 'controller/send_data',
   data: ArrayEnv,
   type: 'POST',
   cache: false,
   contentType: false,
   processData: false,
   before:  '',
   success: function(data) {
   console.log('Ajax Value: '+data);
}}); 

So, when I send the data to the controller without the FILE, everythin goes right, but whenever I send a file it crashes. I dont want to use formData since im getting and validating multiple variables through branchings on the JS.

I've done a lot of research and im really losing hope... is there any way to send a file in the same array that containts the data?


Update:

Actually had to use formData to make it work

   data = new FormData($("#validatedForm")[0]);

   $.ajax({
       url: 'controller/send_data',
       data: data,
       cache: false,
       contentType: false,
       processData: false,
       beforeSend: function() {
         console.log('Load');
     },
       method: 'POST',
      // type: 'POST', // For jQuery < 1.9
       success: function ( data ) {
           console.log( data );
       }
   });
about 4 years ago · Juan Pablo Isaza
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