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

368
Visualizações
Fetch: POST JSON data in react.js

I'm trying to POST a JSON object using fetch. On the client side I see all the data, In the API I get the object with NULL values

That's my call:

const onSubmit = async () => {
console.log(searchCases);
//  handleFormChange();
try {
  await fetch("/api/cases/create_search", {
    method: "POST",
    headers: {
      Accept: "application/json",

      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      searchCases,
    }),
  }).then(async (response) => {
    if (response.ok) {
      //let byteArray = await response.arrayBuffer();
      let byteArray = await response;
      let data = byteArray;
      setNewData(data);
      console.log(data);
    }
  });
} catch (e) {
  console.error(
    'Error: An error was detected in the function "fetch" /api/cases/create_search_case OR in msgpk:',
    e
  );


}
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I'm not sure why do you have to use async/await in side then(). You can try this:

const onSubmit = async () => {
console.log(searchCases);
//  handleFormChange();
try {
  await fetch("/api/cases/create_search", {
    method: "POST",
    headers: {
      Accept: "application/json",

      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      searchCases,
    }),
  }).then(response => {
      let byteArray = response;
      let data = byteArray;
      setNewData(data);
      console.log(data);
    }
  );
} catch (e) {
  console.error(
    'Error: An error was detected in the function "fetch" /api/cases/create_search_case OR in msgpk:',
    e
  );
}
over 4 years ago · Santiago Trujillo Relatório
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