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

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