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

157
Visualizações
return Null Fetch Javascript API

When creating a data with Fetch by javascript, they come as Null when displayed on the screen, but by Postman it is done as normal. You can help? The ID is also shown normally in the html, but author and txt are not

export const listPhrases = async (req: Request, res: Response) => {
    let list = await Phrase.findAll({})
    res.json({list})
}

export const createPhrase = async (req: Request, res: Response) => {
  let { author, txt} = req.body;
  let newPhrase = await Phrase.create({ author, txt });
  res.status(201);
  res.json({ id: newPhrase.id, author, txt });
}
 async function getPhrases () {
             const response = await fetch('http://localhost:4000/frases')
             const data = await response.json()
             const phrase = await (data.list)

             let newPhrases = '';
                phrase.forEach(((item) => {
                    let newPhrasesPost = `
                    <h5>${item.txt}</h5>`
                    newPhrases += newPhrasesPost
                }))
                document.getElementById("phrase").innerHTML = newPhrases;
}
async function newPhrase() {
  let inputPhrase = document.getElementById("inputPhrase").value;
  let author = document.getElementById("author").value;

  let phrasePost = { inputPhrase, author };

  const options = {
    method: "POST",
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify(phrasePost)
  };

  const response = await fetch("http://localhost:4000/frases", options);
  getPhrases();
}
about 4 years ago · Juan Pablo Isaza
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