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

155
Views
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
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!