最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Giving error when retrieving data from Firebase with Javascript - Stack Overflow

programmeradmin2浏览0评论

i included these cdn in my html:

<script src=".6.1/firebase-app.js"></script>

<script src=".1.0/firebase-auth.js"></script>

<script src=".1.0/firebase-database.js"></script> 

<script src="StoreFeatured.js" type="text/javascript"></script>

and here is the store featured code

var firebaseConfig = {
apiKey: "$$$$$$$",
authDomain: "$$$$$$",
databaseURL: "",
projectId: "thegreatpcstore",
storageBucket: "thegreatpcstore.appspot",
messagingSenderId: "302435893791",
appId: "$$$$$$$",
measurementId: "G-0GH3F41E5S"
};
firebase.initializeApp(firebaseConfig);

new function GetData() 
{
    firebase.database().ref('/Products/Motherboard/1').once('value').then(function (snapshot) {

            //var Description = snapshot.val().Description;
            var Name = snapshot.val().Name;
            var Price = snapshot.val().Price;
            var ImageStr = snapshot.val().ImageStr;

            document.getElementById("Mi"+i).src=ImageStr;
            document.getElementById("Mn"+i).innerHTML=Name;
            document.getElementById("Mp"+i).innerHTML=Price;
        }     
    )
}

what am i doing wrong?

im getting these errors:

> firebase-auth.js:206 Uncaught Error: Cannot find the firebase namespace; be sure to include firebase-app.js before this library.
    at firebase-auth.js:206
    at firebase-auth.js:206
    at firebase-auth.js:206
> 
> firebase-database.js:38 Uncaught Error: FIREBASE FATAL ERROR: Failed
> to register the Firebase Database Service (TypeError:
> firebase.INTERNAL.registerService is not a function) 
>     at dd (firebase-database.js:38)
>     at firebase-database.js:245
>     at firebase-database.js:245
> 
> StoreFeatured.js:17 Uncaught TypeError: firebase.database is not a
> function
>     at new GetData (StoreFeatured.js:17)
>     at StoreFeatured.js:13

first line of getdata() is doing problem i think im doing something wrong with cdn... please help

if i remove the cdn it gives one error:

StoreFeatured.js:16 Uncaught TypeError: firebase.database is not a function
at new GetData (StoreFeatured.js:16)
at StoreFeatured.js:13

i included these cdn in my html:

<script src="https://www.gstatic./firebasejs/7.6.1/firebase-app.js"></script>

<script src="https://www.gstatic./firebasejs/3.1.0/firebase-auth.js"></script>

<script src="https://www.gstatic./firebasejs/3.1.0/firebase-database.js"></script> 

<script src="StoreFeatured.js" type="text/javascript"></script>

and here is the store featured code

var firebaseConfig = {
apiKey: "$$$$$$$",
authDomain: "$$$$$$",
databaseURL: "https://thegreatpcstore.firebaseio.",
projectId: "thegreatpcstore",
storageBucket: "thegreatpcstore.appspot.",
messagingSenderId: "302435893791",
appId: "$$$$$$$",
measurementId: "G-0GH3F41E5S"
};
firebase.initializeApp(firebaseConfig);

new function GetData() 
{
    firebase.database().ref('/Products/Motherboard/1').once('value').then(function (snapshot) {

            //var Description = snapshot.val().Description;
            var Name = snapshot.val().Name;
            var Price = snapshot.val().Price;
            var ImageStr = snapshot.val().ImageStr;

            document.getElementById("Mi"+i).src=ImageStr;
            document.getElementById("Mn"+i).innerHTML=Name;
            document.getElementById("Mp"+i).innerHTML=Price;
        }     
    )
}

what am i doing wrong?

im getting these errors:

> firebase-auth.js:206 Uncaught Error: Cannot find the firebase namespace; be sure to include firebase-app.js before this library.
    at firebase-auth.js:206
    at firebase-auth.js:206
    at firebase-auth.js:206
> 
> firebase-database.js:38 Uncaught Error: FIREBASE FATAL ERROR: Failed
> to register the Firebase Database Service (TypeError:
> firebase.INTERNAL.registerService is not a function) 
>     at dd (firebase-database.js:38)
>     at firebase-database.js:245
>     at firebase-database.js:245
> 
> StoreFeatured.js:17 Uncaught TypeError: firebase.database is not a
> function
>     at new GetData (StoreFeatured.js:17)
>     at StoreFeatured.js:13

first line of getdata() is doing problem i think im doing something wrong with cdn... please help

if i remove the cdn it gives one error:

StoreFeatured.js:16 Uncaught TypeError: firebase.database is not a function
at new GetData (StoreFeatured.js:16)
at StoreFeatured.js:13
Share Improve this question asked Dec 29, 2019 at 21:11 Hassaan RazaHassaan Raza 1974 silver badges14 bronze badges 2
  • 2 Shouldn't you be using the same version in all firebase dependencies ? I see 7.6.1 and 3.1.0. – David Magalhães Commented Dec 29, 2019 at 21:39
  • i copied it from an answer did not looked at it :( – Hassaan Raza Commented Dec 29, 2019 at 21:40
Add a ment  | 

2 Answers 2

Reset to default 7

Update both the firebase-auth and firebase-database to the following version:

<script src="https://www.gstatic./firebasejs/7.6.1/firebase-auth.js"></script>
<script src="https://www.gstatic./firebasejs/7.6.1/firebase-database.js"></script>

Instead of using various CDN use a single CDN which include all the library:

script src="https://www.gstatic./firebasejs/7.14.4/firebase.js" 
发布评论

评论列表(0)

  1. 暂无评论