Click to See Complete Forum and Search --> : Server side include with javascript
melone
09-17-2003, 10:25 AM
Hi, I'm trying to write a virtual include line to a page using javascript with no luck
i.e. document.write('<!--#include virtual="mypage.htm"-->') the '#include' seems to bug up the rest of my code, is there any way of doing this????
thanks in advance
Any help is appreciated
AdamGundry
09-17-2003, 10:30 AM
If SSI is working correctly, you should never see the #include, instead getting the contents of the file. And if it isn't working, the text should not affect JS.
Perhaps you could post a link to the page with the problem?
Adam
melone
09-17-2003, 10:53 AM
Hi Adam, thanks for your response
I agree we should never see the '#include' however it is having an issue with the processing of the string and hence giving me errors rather than actually interpreting the command. Unfortunately I can't give you a URL as it is an intranet I'm working on but here's a snippit - I hope it helps...
pageDoc.write("<BODY TOPMARGIN=0 BGCOLOR=\"#B3B3FF\" BACKGROUND=\"*\" onLoad=\"top.control_frame.doDataExchange(false,false);if(top.redraw)top.checkLoad();\">");
pageDoc.write("<!--#include virtual='_include/infonetnav_e.htm'-->"); //this is where my trouble is...
pageDoc.write("<FORM onsubmit=\"return false\">");
Thanks again
AdamGundry
09-17-2003, 10:56 AM
Oh, you mean the SSI is giving an error, not the JS? I'm afraid I'm not exactly an SSI expert, but perhaps some of the others could help you.
Adam
melone
09-17-2003, 01:19 PM
Actually it would seem to be more of a js thing. The include on its own works fine. when I try to pass it through js as in my previous email, I get issues. Is the pound symbol(#) reserved in js? or perhaps, is there a way to 'escape' the '!'?
AdamGundry
09-17-2003, 01:23 PM
Neither symbol should cause a problem, and work fine in IE 6.0 and Mozilla 1.4. Are you aware that if Javascript is writing the SSI, then the SSI will not execute - it has to be read from a SSI page. I had presumed you were executing the SSI so Javascript stored the contents of the include page, not the SSI code itself.
Adam
melone
09-17-2003, 01:37 PM
Sorry Adam, I'm not sure I understand, but if I do I think you are asking if the command is actually being processed. In which case, no would be the answer. As soon as I attempt to load the page I get script errors. My javascript works fine with anything other than the include line, for example my simple document.write will output every other test I have done to the page. Conversly the Include line works fine on any other page I put it on. It's when I try to have JS 'write' the include line to the page so that the page will parse the include that I have problems.
This is why I was asking about the reserved characters thing.
I hope this makes sense, and thanks for your time
AdamGundry
09-19-2003, 02:31 PM
If I understand you correctly, the sequence of instructions is going like this:
1. User gets page with JS code
2. JS code activates, writes SSI to new page
3. SSI does not execute
This will not work because SSI only works from the server, not written by JS. You will need to find another solution to your problem if this is the case.
Adam
Jeff Mott
09-19-2003, 04:47 PM
melone, remember that whatever your SSI statement is including is being stuck into a JavaScript statement, and for the resulting JavaScript to execute correctly the included file must follow all syntax rules. So any single quotes (') or the start of any HTML closing tag (</) or any other special character sequences (e.g., \x00, \n, \) will all be interpreted as code.
melone
09-22-2003, 07:11 AM
Hi guys, - thanks for all you help. I have finally admitted defeat. - you are both right, both about the tags and how javascript 'writes' to the page. I thought there might be a work around. I have come up with a low-tech solution for this, everyone seems happy so far (other than myself).
Great forum, and I appreciate everyone's help
Cheers