为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

慕姐4208626 2022-12-02 17:07:49
我让我的 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>
查看完整描述

1 回答

?
守候你守候我

TA贡献1802条经验 获得超10个赞

这里:


<script>

    fetch('aws api')

    .then(response => response.text())

    .then(contents => console.log(contents))

     document.getElementById("visitors").innerHTML = content

 </script>

content未定义,您的意思可能是contents,但您必须在解决承诺后执行此操作:


<script>

    fetch('aws api')

    .then(response => response.text())

    .then(contents =>{

        console.log(contents);

        document.getElementById("visitors").innerhtml = contents

    })

 </script>


查看完整回答
反对 回复 2022-12-02
  • 1 回答
  • 0 关注
  • 131 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号