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
La base de datos en tiempo real de Firebase no funciona en Chrome

Configuré una base de datos en tiempo real de Firebase, y cuando ejecuto mi código, funciona en Safari pero no funciona en Chrome.

Este es mi enlace de archivo index.js a un archivo html como <script type="module" src="index.js"></script>

 import { initializeApp } from 'https://www.gstatic.com/firebasejs/9.1.2/firebase-app.js'; import { getDatabase, set, ref } from 'https://www.gstatic.com/firebasejs/9.1.2/firebase-database.js'; const firebaseApp = initializeApp({ apiKey: "xxx", authDomain: "xxx", databaseURL: "xxx", projectId: "xxx", storageBucket: "xxx", messagingSenderId: "xxx", appId: "xxx", }); const db = getDatabase(firebaseApp) var x = document.getElementById("Identifiant"); var y = document.getElementById("Password"); function senddata(){ set(ref(db, 'users/' + x.value), { username: x.value, password: y.value }); window.location.href = 'https://www.youtube.com'; }; var btn = document.getElementById('btnconx'); btn.addEventListener('click', senddata);

Entonces esto funciona en Safari, pero en Chrome, me envía a YouTube pero no escribe en la base de datos. Pero si no coloco " window.location.href = 'https://www.youtube.com'; ", enviará los datos a la base de datos incluso en Chrome. ¿Cómo hago que funcione para que después de escribir los datos en la base de datos, envíe al usuario a YouTube (o básicamente a cualquier sitio web)? Tenga en cuenta que el botón "btn" como type="button" y está dentro de un formulario con el método="GET".

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Parece que puede estar redirigiendo su página antes de que tenga la oportunidad de enviar sus datos. Para remediar esto, sugiero hacer que senddata() sea asincrónico y esperar a set(). Esto debería permitir que su página envíe los datos antes de redirigir.

ES6

 async function senddata(){ await set(ref(db, 'users/' + x.value), { username: x.value, password: y.value }); window.location.href = 'https://www.youtube.com'; };

ES5

 function senddata(){ set(ref(db, 'users/' + x.value), { username: x.value, password: y.value }).then(() => { window.location.href = 'https://www.youtube.com'; }); };
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!