📜  js 返回一个承诺 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:49.927000             🧑  作者: Mango

代码示例2
function myAsyncFunction(url) {
  return new Promise((resolve, reject) => {
    const xhr = new XMLHttpRequest();
    xhr.open("GET", url);
    xhr.onload = () => resolve(xhr.responseText);
    xhr.onerror = () => reject(xhr.statusText);
    xhr.send();
  });
}