SSI with javacript - syntax problem.

P

Paul

HI! I am trying to dynamically add content into Div tags with the use of
JavaScript. it loads the page but adds a few characters. the script is
below.

<script language="JavaScript">
document.write('<div id=DivExample>"<!--#include
virtual="/Include_Pages_Asp/Main.htm" --></div>');
</script>

The characters that are added is right after the end of Main.htm page. they
are as follows.

');

I also get this JavaScript error in IE

Line: 48
Char:106
Error:Unterminated string constant.

Since the page does load fully I suspect that Its a small syntax problem but
I just don't know what.

can someone tell me what I am doing wrong?
 
R

rf

Paul said:
HI! I am trying to dynamically add content into Div tags with the use of
JavaScript. it loads the page but adds a few characters. the script is
below.

<script language="JavaScript">
document.write('<div id=DivExample>"<!--#include
virtual="/Include_Pages_Asp/Main.htm" --></div>');
</script>

The characters that are added is right after the end of Main.htm page. they
are as follows.

');

I also get this JavaScript error in IE

Line: 48
Char:106
Error:Unterminated string constant.

That should be a hint.

Count the 's and the "s in the above document.write call.

I see two 's but, oddly (pun intended), three "s. Three "s would usually
cause an unterminated string somewhere. " to open the string but no closing
". You are at the mercy of error correction.

I suspect the first " should not be there.

Cheers
Richard.
 
P

Paul

HI! thanks for responding. It still does not work. I see in source
view that it writes a one line then stops.

I being told that Includes need to happen on the server, this
include directive is being written out on the client by which time it's too
late to include.

Here is the link.
http://www.webcandesign.com/111/main_test_newnew.asp

How do load the page then?

Paul
 
W

web.dev

Paul said:
HI! thanks for responding. It still does not work. I see in source
view that it writes a one line then stops.

I being told that Includes need to happen on the server, this
include directive is being written out on the client by which time it's too
late to include.

Here is the link.
http://www.webcandesign.com/111/main_test_newnew.asp

How do load the page then?

Paul

Hello Paul,

If you're trying to do SSI with javascript, you're going about it all
wrong. It's called Server Side Includes (SSI) for a reason. That being
that it happens on the server side. You can attempt to do Client Side
Includes, but believe me, that will get messy real fast. Here are some
general solutions:

For an ASP page:

<!--#include virtual="filename"-->
or
<!--#include file ="filename"-->

For a PHP page:
require("filename");
or
include("filename");

For a SHTML page:
<!--#include virtual="filename"-->
or
<!--#include file ="filename"-->

Hope this helps.
 
A

ASM

Paul said:
HI! I am trying to dynamically add content into Div tags with the use of
JavaScript. it loads the page but adds a few characters. the script is
below.

<script language="JavaScript">
document.write('<div id=DivExample>"<!--#include
virtual="/Include_Pages_Asp/Main.htm" --></div>');
</script>

<script language="JavaScript"> is uncorrect

a " (dble quote) is missing

<script type="text/javascript">
document.write('<div id="DivExample>"'+
'<!--#include virtual="/Include_Pages_Asp/Main.htm" -->'+
'<\/div>');
</script>

allways an anti-slash before a slash next after a '<'
or :
'<'+'/div>'

and ... what have you in your Main.htm ?
 
R

Randy Webb

ASM said the following on 8/30/2005 7:55 PM:
<script language="JavaScript"> is uncorrect

a " (dble quote) is missing

Where? The script tag you quoted shows the deprecated language attribute
in quotes.
<script type="text/javascript">
document.write('<div id="DivExample>"'+
'<!--#include virtual="/Include_Pages_Asp/Main.htm" -->'+
'<\/div>');
</script>

allways an anti-slash before a slash next after a '<'
or :
'<'+'/div>'

And it still won't work. It is because the include has already occured,
or attempted to occur, before the script is ever executed.
 
A

ASM

Paul said:
HI! thanks for responding. It still does not work. I see in source
view that it writes a one line then stops.

I being told that Includes need to happen on the server, this
include directive is being written out on the client by which time it's too
late to include.

Here is the link.
http://www.webcandesign.com/111/main_test_newnew.asp

How do load the page then?


once more : what's content of 'Main.htm' ?

because in the page is :

document.write(<div id=DivExample>'<!DOCTYPE HTML ... >

and a quote is yet missing ... !
and,
if there if a return carriage in 'Main.htm'
it will not work

You'ld have to set in 'Main.htm' :

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"<br>'+
'"http://www.w3.org/TR/1998/REC-html40-19980424/loose.dtd">

note the quotes (') and plus (+)

so, in your JS :

document.write('<div id="DivExample">'+
'"/Include_Pages_Asp/Main.htm" --></div>');

to get in end

document.write('<div id="DivExample">'+
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"<br>'+
'"http://www.w3.org/TR/1998/REC-html40-19980424/loose.dtd"><\/div>');
 
P

Paul

HI! thanks for the response. I am using it this form because I want to be
able to change the content. I want to be able to replace the include file
from a menu. Is there another way to do this without going this without
using the javascript in the way that I am using it?

Paul
 
P

Paul

HI! I don't the see the different between what you have shown me and what I
have done.

<!--#include virtual="/Include_Pages_Asp/Main.htm" -->

<!--#include virtual="filename"-->

I am using asp. I dont understand the difference that you are pointing out.


Paul
 
P

Paul

I wonder now is there is perhaps an easier way by creating a session
variable to load the string ( path of the include file) and then change the
string value via the menu . would work? this would mean the include file
would not to be modified and it would treated as normal include file. is
this correct?

Paul
 
A

ASM

Paul said:
HI! I don't the see the different between what you have shown me and what I
have done.

the differences are :

'virtual' is to use with a relative link
virtual="../folder/file.htm" : relative / page calling
virtual="/file.htm" : relative / root of site

'file' is to use with absolute link
file="http://sever/site/folder/page.htm"
 
A

ASM

Paul said:
HI! thanks for the response. I am using it this form because I want to be
able to change the content. I want to be able to replace the include file
from a menu. Is there another way to do this without going this without
using the javascript in the way that I am using it?

the change of content with SSI can only be made by loading on server

You can use in SSI server request about url of document
then
get dynamicaly by SSI what it is expected

The JS will run after SSI instructions did
(and here : no need of JS)

here is a plan with SSI only
supposing sent url is this form :
'page.shtml?docType=4T'
or
'page.shtml?docType=41T'


file 'page.shtml' :

<!--#set var="Gotn" value="$QUERY_STRING" -->

<!--#if expr="$Gotn = /. 4T ./" -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/1998/REC-html40-19980424/loose.dtd">

<!--#elif expr="$Gotn = /. 4F ./" -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN"
"http://www.w3.org/TR/1998/REC-html40-19980424/frameset.dtd">

<!--#elif expr="$Gotn = /. 4S ./" -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"
"http://www.w3.org/TR/1998/REC-html40-19980424/strict.dtd">


<!--#elif expr="$Gotn = /. 41T ./" -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">

<!--#endif -->

<html>
<head>
....
</html>


SSI instruction :

<!--#if expr="$Gotn = /. 4T ./" -->

verify if '4T' exists inside value of ssi variable : $Gotn
that's : is string '4T' in url of called page ?

if yes, following html code is writen on page

if not, is ? :
<!--#elif expr=" ... blah ...



You can use this procedure to create on loading your menus
 
A

ASM

Randy said:
ASM said the following on 8/30/2005 7:55 PM:



Where? The script tag you quoted shows the deprecated language attribute
in quotes.
^^^
here : -------------|
And it still won't work. It is because the include has already occured,
or attempted to occur, before the script is ever executed.

no, it is because what is to include is not a string
( doc type in 2 lines I think )
 
P

Paul

HI! And that's why I used virtual because its from the virtual root. I don't
understand why you are pointing it out then.

Paul
 
P

Paul

HI! no what I meant was to create session var to hold the string value on
the include name, not the content of the include. and in the body on the asp
file it would just insert the string name and the browser would replace it
with the include value. this is what I meant. but what I am not sure of the
is if the includes get insert before the <% %> get done. would it help to
put buffer.s=true for the asp file?
 
A

ASM

Paul said:
HI! no what I meant was to create session var to hold the string value on
the include name, not the content of the include.
and in the body on the asp

it is your *.asp
by its conditions relatively to url asked
wich will write the right value (string) in the html code of page

if an external file is needed to decide the value string,
it is inside this *.asp that you have to include external file
in right place

if you did your menus are severa and in separate external files
the *.asp will include the correct one of this files

and browser knows anything of that
server send only html with no more SSI or ASP code
file it would just insert the string name and the browser would replace it
with the include value.

Browser has not to replace this value
The value has to be set ahead on server
this is what I meant. but what I am not sure of the
is if the includes get insert before the <% %> get done. would it help to
put buffer.s=true for the asp file?

if you did read what I give as SSI example
in post : "[HS SSI] SSI with javacript - syntax problem."
and you need to include in SSI a particular file from several :

file 'page.shtml' :

<!--#set var="Gotn" value="$QUERY_STRING" -->
<!--#if expr="$Gotn = /. 4T ./" -->
<!--#include virtual="/doctypes/type_4t.htm" -->
<!--#elif expr="$Gotn = /. 4F ./" -->
<!--#include virtual="/doctypes/type_4f.htm" -->
<!--#endif -->

no need of JS
 
R

Randy Webb

ASM said the following on 8/31/2005 8:38 PM:
^^^
here : -------------|


I am not sure I see what your ^^^ is pointing at, but the issue of " is
not relevant unless it is later used to be part of the quoted text to
JS. Meaning : document.write('anything inside the single quote,
including double quotes " , do not have to be paired. It only matters if
there is an \' inside, as it has to be escaped')

What you seem to have added was an extra " before the id, but you didn't
put it after the ID, you left the errant " outside the > but its still
irellavant.
no, it is because what is to include is not a string
( doc type in 2 lines I think )

No, it is because the include has alread occured, or attempted to occur,
before the script is ever executed.

Browser requests page.
Server assembles page, including included.
Server sends page to browser.
Browser processes page.
JS writes an include statement that was desired to be included in step 2.
Browser displays page, without the include because the server has
already finished step 2.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top