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 (将#修改为@)