简体   繁体   English

在静态html页面中包含一个json文件(不在服务器上托管)

[英]Including a json file in a static html page (not hosted on a server)

I'm midway through setting up automation of my jasmine tests using grunt. 我正在使用grunt设置茉莉花测试自动化。 I have Jasmine (and Istanbul) running fine in node and also a standalone html page that runs the tests. 我的Jasmine(和Istanbul)在节点上运行良好,并且还有运行测试的独立html页面。 However, I only want to maintain one list of src files to include, so I have a json file which lists these in an array. 但是,我只想维护一个要包含的src文件列表,所以我有一个json文件,该文件在数组中列出了这些文件。 I can include it using require() in my Gruntfile, but my plan to include it using ajax in the html page I now realise won't work as I will need to have a server running in order for ajax to work. 我可以在Gruntfile中使用require()来包含它,但是我打算在我现在意识到的html页面中使用ajax来包含它的计划是行不通的,因为我需要运行服务器才能使ajax运行。

So my html page is at file://foo/bar/page.html and the json is in file://foo/bar/my_data.json . 所以我的html页面位于file://foo/bar/page.html ,而json位于file://foo/bar/my_data.json

Is there any other approach I can use to include a JSON file in a static html page which isn't on a server? 我还有其他方法可以用来在服务器上没有的静态html页面中包含JSON文件吗?

这不能解决一般问题,但是事实证明,grunt-contrib-jasmine创建了可在浏览器中使用的持久性specrunner文件,因此源文件列表可以在gruntfile(或单独的json)中维护。 ),并且每次使用grunt运行测试时,specrunner html页面都会自动更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM