W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <body> <h2>JavaScript async / await</h2> <p id="demo"></p> <script> async function getFile() { let myPromise = new Promise(function(myResolve, myReject) { let req = new XMLHttpRequest(); req.open('GET', "/demo/js/mycar.html"); req.onload = function() { if (req.status == 200) { myResolve(req.response); } else { myResolve("File not Found"); } }; req.send(); }); document.getElementById("demo").innerHTML = await myPromise; } getFile(); </script> </body> </html>