我让我的 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>
添加回答
举报
0/150
提交
取消
