从内部文件HTML加载JSON

时间:2023-01-24 10:09:36

Instead of fetching another file to load JSON data (local or remote), is it possible to just import the data into the HTML class?

而不是获取另一个文件来加载JSON数据(本地或远程),是否可以将数据导入HTML类?

The reason why I am asking this is because I would like to create 1 file that contains the HTML, CSS, JQuery, and JSON data without the browser having to fetch any other files.

我之所以这样问是因为我想创建一个包含HTML,CSS,JQuery和JSON数据的文件,而浏览器不需要获取任何其他文件。

Ideas?

1 个解决方案

#1


1  

You can simply put the data in a normal Javascript variable using an object literal.

您可以使用对象文字简单地将数据放入普通的Javascript变量中。

var myData = { ... };

#1


1  

You can simply put the data in a normal Javascript variable using an object literal.

您可以使用对象文字简单地将数据放入普通的Javascript变量中。

var myData = { ... };