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

436
Visualizações
Why my code go on when I delete window.location.href?
    db.collection("chatroom").where("who", "array-contains-any", [Myuid, Selleruid]).get().then((result) => {
  db.collection('chatroom').add(data)
  window.location.href = "/chat.html"
  })

this is part of my code that add a chatroom db to firebase server. It doesn't work, but when I delete window.location.href = "/chat.html" , then it could add data. I can't understand why it works after delete it, and why it doesn't work with that window ~ line.

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

0

Calling add() starts an asynchronous write operation, which happens in the background (to prevent blocking the browser). Your window.location.href = "/chat.html" statement however runs right away, so the write operation gets aborted before it can complete.

To fix this, you'll want to wait for the write operation to be completed before navigating away:

db.collection('chatroom').add(data).then(() => {
  window.location.href = "/chat.html"
})
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