Search code examples
javascripthtmlapachessi

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!

Inspect Element of my Site


Solution

  • 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!