简体   繁体   English

如何SSI包含变量文件名

[英]How to SSI include Variable Filename

I have recently discovered SSI and don't really fully know how it works. 我最近发现了SSI,但还不太了解它是如何工作的。 I have written this javascript code, shown below, that is supposed to turn the end of the link into a text file name (which it does just fine). 我已经编写了如下所示的javascript代码,该代码应将链接的末尾转换为文本文件名(就可以了)。 Then all of the characters necessary to escape are escaped, code below. 然后,所有需要转义的字符都将转义,下面的代码。

var path = window.location.pathname;
var page = path.split("/").pop();
var res = path.replace(".html", ".txt");
var res = res.replace("/Iliad/", "");
console.log(res);
element = document.getElementById('book');
element.innerHTML = "\<\!\-\-\#include virtual="+res+" \-\-\>";

According to the console (inspect element), <!--#include virtual=1.txt --> is added perfectly correctly to an html div container's innerHTML, but it does not incldue the .txt file that it references. 根据控制台(检查元素), <!--#include virtual=1.txt -->可以完全正确地添加到html div容器的innerHTML中,但不会包含它引用的.txt文件。 I have searched the internet and cannot find a solution to this. 我已经搜索了互联网,但找不到解决方案。 Is there something I'm doing wrong? 我做错了什么吗? If so, how do I accomplish this. 如果是这样,我该怎么做。 Thanks! 谢谢!

检查我的网站元素

Server-side includes are processed on the server (hence the name), so long as the server is properly configured. 只要服务器配置正确,服务器端的包含文件就会在服务器上处理(因此而得名)。

Modifying the data in the browser (long after it has left the server) cannot trigger processing of the SSI on the server. 在浏览器中修改数据(离开服务器很长时间之后)无法触发服务器上SSI的处理。


Look to Ajax and DOM manipulation instead. 请改用AjaxDOM操作

Thanks to @Quentin for his speedy answer. 感谢@Quentin的快速回答。 After being told exactly what SSI is meant to do, I searched for another solution. 在确切地了解了SSI的含义之后,我寻找了另一种解决方案。

This worked for me! 对我有用! I modified the code as follows... 我将代码修改如下...

var request = new XMLHttpRequest();
request.open('GET', res, false);
request.send();
var textfileContent = request.responseText;
element = document.getElementById('book');
element.innerHTML = textfileContent;

Hope this helps anyone else! 希望这对其他人有帮助!

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

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