运行 ❯
获取您的
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
转到 Spaces
<!DOCTYPE html> <html> <body> <h1>JavaScript async / await</h1> <p id="demo"></p> <script> async function getFile() { let myPromise = new Promise(function(resolve) { let req = new XMLHttpRequest(); req.open('GET', "mycar.html"); req.onload = function() { if (req.status == 200) { resolve(req.response); } else { resolve("File not Found"); } }; req.send(); }); document.getElementById("demo").innerHTML = await myPromise; } getFile(); </script> </body> </html>