471,338 Members | 1,301 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,338 software developers and data experts.

XMLHTTP object and client-side include

I'm trying to develop a way to include static files in htm pages with
javascript.

I'm trying to use XMLHTTP object this way:

----------------------------------------------------------------------

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>XMLHTTP</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">

var xmlhttp=false;

try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest();
}

function include(xUrl,xId){
xmlhttp.open("GET", xUrl,true);
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
document.getElementById(xId).innerHTML = xmlhttp.responseText;
}
}
xmlhttp.send(null)
}

</script>
</head>
<body>
<script type="text/javascript">
include("header.htm", "xheader");
</script>
<div id="xheader"></div>
<hr>Corpo<hr>
<div id="xfooter"></div>
<script type="text/javascript">
include("footer.htm", "xfooter");
</script>
</body>
</html>

----------------------------------------------------------------------
header.htm and footer.htm are html examples files.

It doesn't work if I call header and footer but if I call only header it
works.
Any help much appreciated.

Best Regards.
--
Fabri
(Non è tuttu oru chiddu chi stralluci, né tuttu veru chiddu ca si dici)
Jul 23 '05 #1
7 2330
Fabri wrote:
I'm trying to develop a way to include static files in htm pages with
javascript.

I'm trying to use XMLHTTP object this way:

----------------------------------------------------------------------

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>XMLHTTP</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">

var xmlhttp=false;

try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest();
}

function include(xUrl,xId){
xmlhttp.open("GET", xUrl,true);
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
document.getElementById(xId).innerHTML =
xmlhttp.responseText;
}
}
xmlhttp.send(null)
}

</script>
</head>
<body>
<script type="text/javascript">
include("header.htm", "xheader");
</script>
<div id="xheader"></div>
<hr>Corpo<hr>
<div id="xfooter"></div>
<script type="text/javascript">
include("footer.htm", "xfooter");
</script>
</body>
</html>

----------------------------------------------------------------------
header.htm and footer.htm are html examples files.

It doesn't work if I call header and footer but if I call only header it
works.
Any help much appreciated.

Best Regards.

why not simply use Server Side Include, or the php equivalent ?
Jul 23 '05 #2
Martin! wrote:
why not simply use Server Side Include, or the php equivalent ?

Because on my hosting-server they are not supported.

--
Fabri
(Non è tuttu oru chiddu chi stralluci, né tuttu veru chiddu ca si dici)
Jul 23 '05 #3
Bonjour à Fabri <no@sp.am> qui nous a écrit :
[...]
function include(xUrl,xId){
xmlhttp.open("GET", xUrl,true);
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
document.getElementById(xId).innerHTML = xmlhttp.responseText;
}
}
xmlhttp.send(null)
}

</script>
</head>
<body>
<script type="text/javascript">
include("header.htm", "xheader");
</script>
<div id="xheader"></div>
<hr>Corpo<hr>
<div id="xfooter"></div>
<script type="text/javascript">
include("footer.htm", "xfooter");
</script>
</body>
</html>
[...]


be carefull, you must place "div" tag before the script, ie :

...
<div id="xheader"></div>
<script type="text/javascript">
include("header.htm", "xheader");
</script>
...

--
Cordialement, Thierry ;-)

Jul 23 '05 #4
Fabri wrote:
Martin! wrote:
why not simply use Server Side Include, or the php equivalent ?


Because on my hosting-server they are not supported.


Then you should switch ASAP to another service provider or wait for, hm,
another year to get XMLHTTPRequest widely implemented. And then it is
likely that you have a Web where exploits let emerge UAs where this single
feature, short of disabling client-side scripting completely or not even
have it supported in the first place, can be disabled. Fortunately,
hosting prices would have dropped by then as well.

BTW: Your sender address is forged which violates/disregards Internet
standards, most certainly the Acceptable Use Policy of your Usenet access
provider (NGI S.p.A.) and Netiquette. Change this ASAP or prepare to face
the consequences.
PointedEars
--
Der Beweis ist ein Götze, vor dem der Mathematiker sich foltert.
-- Sir Arthur Stanley Eddington (1882-1944)
Jul 23 '05 #5
Thomas 'PointedEars' Lahn wrote:
Fabri wrote:

Martin! wrote:
why not simply use Server Side Include, or the php equivalent ?
Because on my hosting-server they are not supported.

Then you should switch ASAP to another service provider or wait for, hm,
another year to get XMLHTTPRequest widely implemented.


It is supported in perhaps 90% of browsers on the web, how much more
"widely" do you want it implemented?

<snip>
BTW: Your sender address is forged which violates/disregards Internet
standards, most certainly the Acceptable Use Policy of your Usenet access
provider (NGI S.p.A.) and Netiquette. Change this ASAP or prepare to face
the consequences.


Please tell me we are not going to go through this childish juvenile
bullshit again about email addresses?

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Jul 23 '05 #6
You could also consider using iframes. They have their own set of
issues, but they are simple to implement.

Jul 23 '05 #7
In article <2L********************@comcast.com>, Hi************@aol.com
enlightened us with...

Please tell me we are not going to go through this childish juvenile
bullshit again about email addresses?


His childish bullshit about email addresses and attributions is why he's one
of only two people in my killfile. He spends more time going on about what
other people did wrong in their postings than any other topic. It negates the
useful stuff he posts.

Some people need to learn that they aren't the 'net police. Until they do, I
don't need to take up my valuable time reading their crap.

/ wishes there was a way to kill responses to this shit without killfiling
the people relying...

--
--
~kaeli~
If a turtle doesn't have a shell, is he homeless or naked?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Martin Waller | last post: by
6 posts views Thread by Krzysztof Kubiak | last post: by
3 posts views Thread by kajol | last post: by
5 posts views Thread by bboyle18 | last post: by
1 post views Thread by Kapil Shah | last post: by
1 post views Thread by Dave H | last post: by
1 post views Thread by daninbrum | last post: by
1 post views Thread by Andrea Cogliati | last post: by
1 post views Thread by mirandacascade | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.