Import code into html file without using php?

Status
Not open for further replies.

Connor

Active Member
136
2011
63
0
First off, I cannot use PHP because for some reason it doesn't work with the server I'm on. If I could use PHP I'd be done with this already but I'm not allowed to change this or update the server in any way so I need to somehow find a workaround for the following problem.

My problem is that I need to store the side navigation in another file that every html file loads the side navigation from so when you want to change a menu item you don't have to edit about 50 html files to change the menu. I can use javascript though, so I was wondering if through js you could get the side navigation code from one file, assign it to a var, and insert the var into all of the other html files. Before I even get started trying to code this I need to know, is this even possible?

EDIT: found a way to do it kind of:
Code:
var txtfile = new XMLHttpRequest();
    var lines 
    txtfile.open("GET", "url" , true);
    txtfile.onreadystatechange = function(){
     if (txtfile.readyState === 4){
      if (txtfile.status === 200){
       alltext = txtfile.responseText;
       lines = txtfile.responseText.split("\n");
       for (var i = 0; i < lines.length; i++){
        document.write(lines[i]);
       }
      }
     }
    }
    txtfile.send(null);
 
Last edited:
1 comment
No offense but why would you be on a server that PHP doesn't work on? That's such a basic function. I would move to another host if possible. It will make life easier for you in the long run.
 
Status
Not open for further replies.
Back
Top