Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/470.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从获取请求获取html_Javascript_Fetch - Fatal编程技术网

Javascript 从获取请求获取html

Javascript 从获取请求获取html,javascript,fetch,Javascript,Fetch,我试图从api响应中获取html。如果执行以下提取请求: const fetchHtml = () => { return fetch('local:8080/api/getHtml') .then((response) => { console.log("Response:"); console.log(response.text()); }) .then((data) => { console.log("Dat

我试图从api响应中获取html。如果执行以下提取请求:

const fetchHtml = () => {
  return fetch('local:8080/api/getHtml')
    .then((response) => {
      console.log("Response:");
      console.log(response.text());
    })
    .then((data) => {
      console.log("Data:");
      console.log(data);
    });
  };
};
我收到以下控制台消息:

Response:
Promise {<pending>}
  __proto__: Promise
  [[PromiseStatus]]: "resolved"
  [[PromiseValue]]: "<html><head><title>Your interest in PROGRAM_NAME</ `Show 108 096 more Copy`"
Data:
undefined
响应:
承诺{}
__承诺
[[PromiseStatus]]:“已解决”

[[PromiseValue]]:“您对程序的兴趣_NAME您必须返回response.text from。然后

const fetchHtml=()=>{
返回fetch('local:8080/api/getHtml')
。然后((响应)=>{
返回response.text();
})。然后((文本)=>{
console.log(文本);
});
};
};