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

139
Visualizações
Does not clear the form when Post fails

I am trying to Post a form. When Post is successful the form gets cleared. However in case Post fails I don't want to clear the form. How should I update below code so form doesn't clear in case Post fails?

*const form = document.querySelector("#create-form")
const foodName = document.querySelector("#create-name")
const carbs = document.querySelector("#create-carbs")
const protein = document.querySelector("#create-protein")
const fat = document.querySelector("#create-fat")

form.addEventListener("submit", event => {
event.preventDefault()
//console.log(carbs.value)
const operation = async (name,carbs, protein, fat) =>{
const response = await fetch("https://firestore.googleapis.com/v1/projects/jsdemo-3f387/databases/(default)/documents/random12345610",{
method: "POST",
body: JSON.stringify({
fields: {
    name: { stringValue: name },
    carbs: { integerValue: carbs },
    protein: { integerValue: protein },
    fat: { integerValue: fat }
  }
})
})
try{
const data = await response.json()}
catch(error){return;}
}
operation(foodName.value, carbs.value, protein.value, fat.value)

foodName.value = "";
    carbs.value = "";
    protein.value = "";
    fat.value = "";
})*
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