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

151
Visualizações
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 à 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