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

366
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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