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

234
Visualizações
Unable to POST data to database through react

consider the following button:

<Button variant="outlined" id='nextcnfbtn' className='mx-auto' style={{ "width": c === 1 ? "30%" : "60%" }} disabled={isError}
                    onClick={(c) => {
                        if (c === 1) {
                            async function postData(url = `${host}/api/bookings/addbooking`, bookingData) {
                                console.log("posting data");
                                const response = await fetch(url, {
                                    method: 'POST', 
                                    mode: 'cors',
                                    headers: {
                                        'Content-Type': 'application/json',
                                        "auth-token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7ImlkIjoiNjIxN2NkOGEwZTI4ZTI3MDM4YmYxZmYwIn0sImlhdCI6MTY0NTcyNzExNH0.UrN2hTukNN5uZlT-AckpHANli6x0Gk3pC97NItKnxZs"
                                    },
                                    
                                    body: JSON.stringify(bookingData)
                                });
                                console.log(response.json());
                            }
                            postData();
                        }
                        setC(1);
                    }}
     >{c === 1 ? "Book!" : "Next"}</Button>

so the state variable c, is used to check which step in the form filling process the user is in, now on click of the button, if the state of c === 1, then I've defined a function to post the data, and later called it. setC(1) is done for the previous step when c ===0, anyways I know that the state of C is 1 because the Button shows "Book!", but its not entering the postData function at all .

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

change the line instead "auth-token" change to "Authorization"

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