繁体   English   中英

如何摆脱 JS 控制台中未定义/未定义的消息

[英]How do i get rid of the not defined/undefined message in my JS console

我让我的 Javascript 与我的 API 网关对话,我的计数器一直在上升,但是在我的控制台上显示“未定义”,我不确定如何解决这个问题。 我不确定我的代码发生了什么变化,但不是我收到一条不同的消息,而不是通常的“未定义”。

fetch('https://wwrr7r0kj5.execute-api.eu-west-2.amazonaws.com/dev/')
   .then(response => response.text())
   .then(contents =>{
        console.log(contents);
        document.getElementById("visitors").innerHTML = contents
})

 Promise {<pending>}
 VM126:4
 296

 <script>
    fetch('aws api')
    .then(response => response.text())
    .then(contents => console.log(contents))
     document.getElementById("visitors").innerhtml = content
 </script>

<div>
    <p  style="text-align: center;color: white;"> 
    Visitors: <span id="visitors">0</span> 
    </p>
</div>

这里:

<script>
    fetch('aws api')
    .then(response => response.text())
    .then(contents => console.log(contents))
     document.getElementById("visitors").innerHTML = content
 </script>

content没有定义,你的意思可能是contents ,但你必须在 promise 解决后做:

<script>
    fetch('aws api')
    .then(response => response.text())
    .then(contents =>{
        console.log(contents);
        document.getElementById("visitors").innerhtml = contents
    })
 </script>

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM