i have built one system like shopping cart using js and firebase as database, after the transaction is success, i have to store the data from "Mycart" node to the "package history", also after finish insert all data to package history node, i need to delete the data from my cart node. the problem that i face is, the data is remove before i insert to database. there some logic error that i face. here the code.
deleteNode(updateHistory); // after the transaction is success
function updateHistory() {
var database = firebase.database();
var ref = database.ref("mycart/" + uid);
ref.on('value', gotData, errData);
}
function gotData(data) {
// code to insert to PurchaseHistory
}
function error(err) {
//
}
function deleteNode() {
updateHistory();
var database = firebase.database();
var refremove = database.ref("mycart/" + uid);
refremove.remove();
}
function gotData(data){
dataRef.set("I'm writing data", function(error) {
if (error) {
alert("Data could not be saved." + error);
} else {
alert("Data saved successfully.");
//remove here
}
})
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.