This is the code the I used to send data from web using javascript to firebase but it doesn't work.
The authentication worked pretty well but other functions didn't work. I want to insert to the tours in the firebase new tour.
In the admin website there's a page called new tour that the admin going to fill the required info and then it goes to the firebase so basically the admin going to use this website to manage the firebase.
<!--firebase-->
<script src="https://www.gstatic.com/firebasejs/7.5.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.5.0/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.5.0/firebase-firestore.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.5.0/firebase-storage.js"></script>
<script src="/__/firebase/7.5.0/firebase-firestore.js"></script>
<script src="/__/firebase/init.js"></script>
<script>
// Your web app's Firebase configuration
var firebaseConfig = {
apiKey: "",
authDomain: "",
databaseURL: "",
projectId: "",
storageBucket: "",
messagingSenderId: "",
appId: "",
measurementId: "[enter image description here][1]"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
firebase.analytics();
/*
if (document.getElementById('opt1').checked) {
choose = document.getElementById('opt1').value;
chooseAr = 'جولة إرشادية ذاتية';
}
else {choose = document.getElementById('opt2').value;
chooseAr = "بمساعدة مرشد";
} */
var database = firebase.database();
function writeUserData(tourId, ArDay, EnDay, TourDur, TourGu, TimeInput, chooseAr, choose) {
var tourId = document.getElementById(TourNumber).value;
var ArDay = document.getElementById(ArabicDay).value;
var EnDay = document.getElementById(EnglishDay).value;
var TourDur = document.getElementById(TourDuration).value;
var TourGu = document.getElementById(TourGuide).value;
var TimeInput = document.getElementById(TimeI).value;
// var option = document.getElementById(TourType).value;
var choose = 'self tour';
var chooseAr = 'جولة إرشادية ذاتية';
firebase.database().ref('tours/' + tourId).set({
dayAR: ArDay,
dayEN: EnDay,
duration: TourDur,
guide: TourGu,
time: TimeInput,
typeAR: chooseAr,
typeEN: choose
});
}
function writeNewTour(tourId, ArDay, EnDay, TourDur, TourGu, TimeInput, chooseAr, choose) {
var tourId = document.getElementById(TourNumber).value;
var ArDay = document.getElementById(ArabicDay).value;
var EnDay = document.getElementById(EnglishDay).value;
var TourDur = document.getElementById(TourDuration).value;
var TourGu = document.getElementById(TourGuide).value;
var TimeInput = document.getElementById(TimeI).value;
// var option = document.getElementById(TourType).value;
var choose = 'self tour';
var chooseAr = 'hj';
// A post entry.
var postData = {
dayAR: ArDay,
dayEN: EnDay,
duration: TourDur,
guide: TourGu,
time: TimeInput,
typeAR: chooseAr,
typeEN: choose
};
// Get a key for a new Post.
var newPostKey = firebase.database().ref().child('tours').push().key;
// Write the new post's data simultaneously in the posts list and the user's post list.
var updates = {};
updates['/tours/' + newPostKey] = postData;
return firebase.database().ref().update(updates);
}
/*fileButton.addEventListener('change', function (e) {
var file = e.target.files[0];
var storageRef = firebase.storage().ref("shops/newFile.png");
task= storageRef.put(file);
task.on(state_changed,
function error(err){
},
function complete() {
}
)
}); */
</script>
<!--firebase-->
Aucun commentaire:
Enregistrer un commentaire