Javascript 在firestore中存储数据后,如何重定向到另一个html文件?
我首先在firebase实时数据库和 现在我把它改成了firestore,但现在我不太清楚我该怎么做 数据发布到firestore后重定向我尝试添加location.href= ""; 在下面 log(“文档成功写入!”); 是,它重定向并存储数据 我注意到,当我等待2秒钟后,它确实起了作用 单击窗口上的“确定”按钮。警报(“已发送约会请求! 请等待您的电子邮件确认,否则我们会将您发送回!”)但没有人会在您单击“确定”按钮之前等待2秒钟, 对吧?Javascript 在firestore中存储数据后,如何重定向到另一个html文件?,javascript,firebase,google-cloud-firestore,Javascript,Firebase,Google Cloud Firestore,我首先在firebase实时数据库和 现在我把它改成了firestore,但现在我不太清楚我该怎么做 数据发布到firestore后重定向我尝试添加location.href= ""; 在下面 log(“文档成功写入!”); 是,它重定向并存储数据 我注意到,当我等待2秒钟后,它确实起了作用 单击窗口上的“确定”按钮。警报(“已发送约会请求! 请等待您的电子邮件确认,否则我们会将您发送回!”)但没有人会在您单击“确定”按钮之前等待2秒钟, 对吧? //我首先在firebase实时数据库中使用了这
//我首先在firebase实时数据库中使用了这段代码,它工作并重定向了
风险值数据={
名字:名字,
LastName:LastName,
联系人:cPhone,
性别:输入性别,
生日:B日,
地址:inputAddress,
城市:输入城市,
省:输入州,
Zip:inputZip,
电子邮件:exampleInputEmail1,
消息:inputMessage,
诊所:输入诊所
};
var firebaseRef=firebase.database().ref();
firebaseRef.push(数据,(错误)=>{
如果(错误){
console.log('error');
}否则{
location.href=”https://dr-elvic-tengco-web.firebaseapp.com/ThankYou.html";
}
})
//现在这是消防商店
//实时数据库
函数getInfo(){
var firstName=document.getElementById(“firstName”).value;
var lastName=document.getElementById(“lastName”).value;
var cPhone=document.getElementById(“cPhone”).value;
var exampleInputEmail1=document.getElementById(“exampleInputEmail1”).value;
var Bday=document.getElementById(“Bday”).value;
var inputGender=document.getElementById(“inputGender”).value;
var inputAddress=document.getElementById(“inputAddress”).value;
var inputCity=document.getElementById(“inputCity”).value;
var inputState=document.getElementById(“inputState”).value;
var inputZip=document.getElementById(“inputZip”).value;
var inputMessage=document.getElementById(“inputMessage”).value;
var inputClinic=document.getElementById(“inputClinic”).value;
如果(!firstName | | |!lastName | |!cPhone | |!示例InputEmail1 | |!Bday |!inputGender | |!inputAddress |!inputCity | |!inputState |!inputZip | |!inputMessage | |!inputClinic){
window.alert(“请填写表单!出于安全目的,页面将重新加载”)
document.getElementById(“gbutton”).disabled=true;
document.location.reload()
}否则{
window.alert(“已发送约会请求!请等待您的电子邮件确认,否则我们会将您发送回来!”)
var db=firebase.firestore();
db.collection(“Requests”).doc().set({
名字:名字,
LastName:LastName,
联系人:cPhone,
性别:输入性别,
生日:B日,
地址:inputAddress,
城市:输入城市,
省:输入州,
Zip:inputZip,
电子邮件:exampleInputEmail1,
消息:inputMessage,
诊所:输入诊所
})
.然后(函数(){
log(“文档成功写入!”);
location.href=”https://dr-elvic-tengco-web.firebaseapp.com/ThankYou.html";
})
.catch(函数(错误){
console.error(“编写文档时出错:”,错误);
});
}
}
我通过使用setTimeout找到了一个替代方法 .然后(函数(){ log(“文档成功写入!”)
我通过使用setTimeout找到了一个替代方法 .然后(函数(){ log(“文档成功写入!”)
尝试添加
window.location.href=”https://www.example.com“;
在console.log下面(“文档编写成功!”)
已经这样做了,但它不起作用。window.location.href运行得很快,发生的事情就像它的过程与数据的发送重叠,所以数据不会发送到firestore。我需要回调之类的东西,关于我在firebase realtime数据库的第一个代码中所做的事情,我不确定如何做。仍在研究如何添加window.location.href=”https://www.example.com“;
在console.log下面(“文档编写成功!”)
已经这样做了,但它不起作用。window.location.href运行得很快,发生的事情就像它的过程与数据的发送重叠,所以数据不会发送到firestore。我需要回调之类的东西,关于我在firebase realtime数据库的第一个代码中所做的事情,我不确定如何做。仍在研究它
//I had this code first on firebase realtime database-this worked and redirected
var data = {
FirstName: firstName,
LastName: lastName,
Contact: cPhone,
Gender: inputGender,
Birthdate: Bday,
Address: inputAddress,
City: inputCity,
Province: inputState,
Zip: inputZip,
Email: exampleInputEmail1,
Message: inputMessage,
Clinic: inputClinic
};
var firebaseRef = firebase.database().ref();
firebaseRef.push(data, (error) => {
if (error) {
console.log('error');
} else {
location.href = "https://dr-elvic-tengco-web.firebaseapp.com/ThankYou.html";
}
})
//and now this is the firestore
<script>
//FOR REALTIME DABASE
function getInfo() {
var firstName = document.getElementById("firstName").value;
var lastName = document.getElementById("lastName").value;
var cPhone = document.getElementById("cPhone").value;
var exampleInputEmail1 = document.getElementById("exampleInputEmail1").value;
var Bday = document.getElementById("Bday").value;
var inputGender = document.getElementById("inputGender").value;
var inputAddress = document.getElementById("inputAddress").value;
var inputCity = document.getElementById("inputCity").value;
var inputState = document.getElementById("inputState").value;
var inputZip = document.getElementById("inputZip").value;
var inputMessage = document.getElementById("inputMessage").value;
var inputClinic = document.getElementById("inputClinic").value;
if (!firstName || !lastName || !cPhone || !exampleInputEmail1 || !Bday || !inputGender || !inputAddress || !inputCity || !inputState || !inputZip || !inputMessage || !inputClinic) {
window.alert("Please Complete the Form! The Page will Reload For Security Purpose")
document.getElementById("gbutton").disabled = true;
document.location.reload()
} else {
window.alert("Appointment Request Sent! Please wait for a confirmation on your Email or We'll txt you back!")
var db = firebase.firestore();
db.collection("Requests").doc().set({
FirstName: firstName,
LastName: lastName,
Contact: cPhone,
Gender: inputGender,
Birthdate: Bday,
Address: inputAddress,
City: inputCity,
Province: inputState,
Zip: inputZip,
Email: exampleInputEmail1,
Message: inputMessage,
Clinic: inputClinic
})
.then(function() {
console.log("Document successfully written!");
location.href = "https://dr-elvic-tengco-web.firebaseapp.com/ThankYou.html";
})
.catch(function(error) {
console.error("Error writing document: ", error);
});
}
}
setTimeout(function() {
location.href = "https://dr-elvic-tengco-web.firebaseapp.com/ThankYou.html";
}, 2000);
})
.catch(function(error) {
console.error("Error writing document: ", error);
});