简体   繁体   中英

How to SSI include Variable Filename

I have recently discovered SSI and don't really fully know how it works. 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). 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. 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.


Look to Ajax and DOM manipulation instead.

Thanks to @Quentin for his speedy answer. After being told exactly what SSI is meant to do, I searched for another solution.

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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