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

365
Views
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 answers
Answer question

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 Report
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!