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

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