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

103
Visualizações
This is a React JS Fetch with a failing POST method

I have a simple react application and I am trying to request and post the method and render out the response inside my return div. I am getting a 400 error in my dev tool (network). I have debugged the app so many times. I just can not hit a jackpot. If you run the endpoints in postman using the token attached you will see the response...

import React from "react";

function Checkout() {
  const handleSubmit = () => {
    const token = "TOKEN";
    const data = {
      transactionReference: "string",
      paymentMethod: "CreditCard",
      checkoutOrderUrl: "http://www.test.com/",
      user: {
        name: "string",
        msisdn: "+27610983142",
        email: "test@test.com",
      },
      payementMethodDetail: {
        RedirectUrl: "http://www.test.com",
        PurchaseEventWebhookUrl: "http://www.test.com",
      },
      bundle: [
        {
          productCode: "311",
          amount: 100,
          currencyCode: "ZAR",
          quantity: 1,
        },
      ],
    };
    const requestOptions = {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        Authorization: `Bearer ${token}`,
      },
      body: data,
    };
    fetch(
      "--------",
      requestOptions
    )
      .then((response) => response.json())
      .then((res) => console.log(res));
  };

  return (
    <div className="App">
      <button type="submit" onClick={handleSubmit}>
        Post Data
      </button>
    </div>
  );
}

export default Checkout;
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You are not serializing your object to JSON. You're actually sending [object Object]. Use JSON.stringify for that:

const requestOptions = {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    Authorization: `Bearer ${token}`,
  },
  body: JSON.stringify(data), // <-- here!
};
about 4 years ago · Juan Pablo Isaza Relatório

0

Inside requestOptions you need credentials: 'include', most likely its CORS related issue.

about 4 years ago · Juan Pablo Isaza 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