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

434
Views
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 answers
Answer question

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 Report
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!