我正在创建一个应用程序,需要一种方法来获取 url HTML,然后将返回值放入文本区域中进行编辑和复制。
文本区域部分我可以自己做。现在我需要发送请求并获取 HTML 网址。
我已经使用了 HttpRequest() 和 fetch,但不知道该去哪里。我也愿意接受 ajax 或 jquery。
我预计问题是您需要从 https 响应访问文本。试试这个:
fetch('https://example.com/your-html file.html')
.then(response => response.text())
.then(html => {
// Handle the HTML content here. Store it to a string or whatever you want to get it to the TextArea
console.log(html);
})
.catch(error => {
// catch failure
console.error('Error fetching HTML:', error);
});