This is the code the I used to send data from web using javascript to firebase but it doesn't work.
(这是我用来使用javascript从网络向Firebase发送数据的代码,但是它不起作用。)
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.
(在管理网站中,有一个名为new tour的页面,该管理员将填写所需的信息,然后转到Firebase,因此基本上,管理员将使用此网站来管理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-->
ask by lama - translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…