微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

XMLHTTPREQUEST 问题,而我附加到潜入 html

如何解决XMLHTTPREQUEST 问题,而我附加到潜入 html

嘿朋友我刚开始学习XMLHttpRequest 我在 console.log 上写了这段代码,但是当我将它附加到 HTML 时,它向我显示 Object Object 我知道它的对象,但我想在 HTML HELP PLEASE 中显示对象内的数据

  return new Promise((resolve,reject) => {
    let myRequest = new XMLHttpRequest();
    myRequest.onload = function () {
      if (this.readyState === 4 && this.status === 200) {
        resolve(JSON.parse(myRequest.responseText));
      } else {
        reject(Error(this.statusText));
      }
    };

    myRequest.open("GET",apiURL,true);
    // send request to API
    myRequest.send();
  });
};

apiGenerator("https://random-data-api.com/api/stripe/random_stripe").then(
  (resulit) => {
    console.log(resulit);
    let newElement = document.createElement("div");
    let elementText = document.createTextNode(resulit);
    newElement.appendChild(elementText);
    document.body.appendChild(...newElement);
  },(error) => console.log(error)
);

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。