简体   繁体   English

未捕获(承诺)类型错误:无法读取 null 的属性“innerHTML”?

[英]Uncaught (in promise) TypeError: Cannot read property 'innerHTML' of null?

I am try to fetch imageURL and name from cloud firestore database.But retrieval get failed and showing no value on the web page.我正在尝试从云 Firestore 数据库中获取 imageURL 和名称。但是检索失败并且在 web 页面上没有显示任何值。 After inspecting the correct value is being printed inside the console but along with that console is showing some error in innerHTML.检查正确的值后,控制台内正在打印,但与该控制台一起,在 innerHTML 中显示了一些错误。 Can anyone please overview the both code(Html & Js) and tell me where is the error and mistakes i have done?谁能概述一下这两个代码(Html & Js)并告诉我我犯的错误和错误在哪里?

Error:错误:

defualt.js:22 Uncaught (in promise) TypeError: Cannot read property 'innerHTML' of null
at defualt.js:22
at database.ts:2202
at document_set.ts:97
at Wg.ut (sorted_map.ts:324)
at Wg.ut (sorted_map.ts:323)
at Hg.ut (sorted_map.ts:136)
at k_.forEach (document_set.ts:96)
at gN.forEach (database.ts:2201)
at defualt.js:8

Can anyOne please reffer me how to fetch ImageUrl from cloud firestore database to website.任何人都可以请参考我如何从云防火墙数据库中获取 ImageUrl 到网站。 I am making Website which will only fetch user Profile Image and Name together and display inside the website.我正在制作网站,它只会同时获取用户个人资料图像和名称并显示在网站内。 I have already upload the image inside the firebase Storage and save ImageUrl link inside the cloud firestore database.我已经在 firebase 存储中上传了图像,并将 ImageUrl 链接保存在云 Firestore 数据库中。 I just wanted to retrieve Profile image and name which is already stored inside my cloud database.我只是想检索已经存储在我的云数据库中的个人资料图像和名称。

Please help me i am facing this issue from last 5 days its gonna be haptic for me to find the result.请帮助我,我从过去 5 天开始就面临这个问题,我很容易找到结果。 I have read the documentation of firestore but it is not so very helpful to me.我已经阅读了 firestore 的文档,但它对我没有太大帮助。 I have try the below code but it is not working the stored values are not我尝试了下面的代码,但它不起作用存储的值不是

Js code: js代码:

db.collection("student entry").get().then(function(querySnapshot) {
  querySnapshot.forEach(function(doc) {
      // doc.data() is never undefined for query doc snapshots
      console.log(doc.id, " => ", doc.data());

      var posts_div=document.getElementById('#posts');
 posts.innerHTML="";
 var data=doc.data();
 console.log(data);
for(let[key,value] of Object.entries(data)){
posts_div.innerHTML="<div class='col-sm-4 mt-2 mb-1'>"+
"<div class='card'>"+
"<img src='"+value.image+"' style='height:250px;'>"+
"<div class='card-body'><p class='card-text'>"+value.fname+"</p>"+
"<button class='btn btn-danger' id='"+key+"' onclick='delete_post(this.id)'>Delete</button>"+
"</div></div></div>"+posts_div.innerHTML;

}
  });
});

HTML code: HTML 代码:

<html>
    <head>
        <title>Blogs</title>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    </head>
    <body>
        <div class="container mt-2">

            <div class="row mt-4" id="posts">

            </div>

        </div>

<!-- The core Firebase JS SDK is always required and must be listed first...make sure you remove -app from below line -->
<script src="https://www.gstatic.com/firebasejs/7.14.2/firebase.js"></script>

<script>
    // Initialize Firebase
    var config = {
        apiKey: " ",
        authDomain: " ",
       databaseURL: " ",
       projectId: " ",
       storageBucket: " ",
      messagingSenderId: " ",
      appId: " ",
      measurementId: " "
    };
    firebase.initializeApp(config);
    var db = firebase.firestore();
    db.settings({ timestampsInSnapshots: true }); 
</script>


        <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
        <script src="defualt.js"></script>
    </body>
</html>

在此处输入图像描述

You don't need # when using getElementById .使用getElementById时不需要# document.getElementById('posts'); should work.应该管用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未捕获的类型错误:无法读取 null 的属性“innerHTML” - Uncaught Typeerror: cannot read property 'innerHTML' of null 未捕获的类型错误:无法读取 null 的属性“innerHTML” - Uncaught TypeError: Cannot read property 'innerHTML' of null 未捕获(承诺)TypeError:无法将属性&#39;innerHTML&#39;设置为null - Uncaught (in promise) TypeError: Cannot set property 'innerHTML' of null Javascript函数返回Uncaught TypeError:无法读取null的属性“ innerHTML” - Javascript function returns Uncaught TypeError: Cannot read property 'innerHTML' of null 未捕获的TypeError:取消选中复选框时无法读取null的属性&#39;innerHTML&#39; - Uncaught TypeError: Cannot read property 'innerHTML' of null when unchecking checkbox 未捕获(承诺)类型错误:无法读取 null 的属性“样式” - Uncaught (in promise) TypeError: Cannot read property 'style' of null 未捕获(承诺)类型错误:无法读取 null 的属性“insertBefore” - Uncaught (in promise) TypeError: Cannot read property 'insertBefore' of null ERROR 错误:未捕获(承诺中):TypeError:无法读取 null 的属性“isAdmin” - ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'isAdmin' of null 未捕获(承诺)类型错误:无法读取 null 的属性“ownerDocument” - Uncaught (in promise) TypeError: Cannot read property 'ownerDocument' of null 未捕获的TypeError:无法将属性&#39;innerHTML&#39;设置为null - Uncaught TypeError: Cannot set property 'innerHTML' of null
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM