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

150
Views
Post data in Ajax call arrays converted to strings?

I'm trying to send arrays as post variables in an Ajax call using formData. For some reason they are getting converted to strings when I look in the console. I can't update the functions accepting the data to accept strings, they must accept arrays. I was reading about using the serialize function but then I'm also left with strings...so I'm not sure how to do this. Here is the code I have so far:

function submitSearch(method) {

  if (method==='ajax_getPrograms') {
      fields = ['pkProgramID','fldName','fldOrganization','fldProgramStartDate','fldProgramEndDate'];
  }
  if (method==='ajax_getPlots') {
      fields = ['id','lat','long','plotSampleYear'];      
  }  
  if (method==='ajax_getTrees') {
      fields = ['id','species','DBH','treeStatus','treeSampleYear'];      
  }   
  var posturl = baseURL + "data/"+method;
  var formData = new FormData();

  formData.append('fields',fields);

  $.ajax({
            url: posturl,
            cache: false,
            data: formData,
            method: 'POST',
            mimeType: "multipart/form-data",
            contentType: false,
            processData: false,
            type: 'POST',
            error: function (xhr, status, error) {
                console.log(xhr);
                console.log(status);
                console.log(error);
            },
            success: function (data) {
 
                console.log(data);

            }
        });
}

When I submit that I get an error that my function is receiving a string and not an array, and this is what I see in the network tab of the console: enter image description here

Any help is appreciated, thank you!

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!