在内部HTML中显示异步方法的结果



大家好,我有一个问题,如何在内部HTML中显示异步方法的结果?

<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
let y="";
async function handlePress(){
const URL = "https://ewserver.di.unimi.it/mobicomp/treest/register.php"
console.log("Sending request")
const c= await fetch(URL);
return await c.json(); 
}
function loadData(){
this.handlePress().then(sids => {
document.getElementById("#demo").innerHTML = sids;
});
}
loadData()
</script>
</body>
</html>

在内部HTML中,我想打印函数handlePress((的结果。我该怎么做?到控制台,它告诉我innerHTML是空的。为什么?

getElementById参数不允许#

innerHTML必须是字符串

let y = "";
async function handlePress() {
const URL = "https://ewserver.di.unimi.it/mobicomp/treest/register.php"
console.log("Sending request")
const c = await fetch(URL);
return await c.json();
}
function loadData() {
this.handlePress().then(sids => {
document.getElementById("demo").innerHTML = sids.sid
});
}
loadData()
<p id="demo"></p>

最新更新