如何通过HTTP将HTML文件加载到字符串中以在JavaScript中使用

How do I load an HTML file over HTTP into a string for use in JavaScript?

本文关键字:JavaScript 字符串 HTTP 何通过 HTML 加载 文件      更新时间:2023-09-26

我想以字符串的形式从JavaScript访问HTML文件(makemeastring.html)。jQuery的.load似乎不起作用。

$.get('makemeastring.html').then(function (data) {
  console.log(data);
}).fail(function () {
  // Error occurred, handle it here
});

jQuery的.load()函数将数据放入DOM元素中。你不想那样,所以.get()就可以了。

http://api.jquery.com/jquery.get/