0

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

R2bEEaton
  • 51
  • 1
  • 10

2 Answers2

1

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.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
0

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!

R2bEEaton
  • 51
  • 1
  • 10
  • `XMLHttpRequest`/GET works similar to SSI but the visitor browser will do it ,I'm almost on your position (see my [question](https://stackoverflow.com/q/54496084/3019002) ) , as I need to change inner page contents according to pre given(from the server side) values , if you have better idea please give m a hint . – Salem Feb 02 '19 at 22:43