473,322 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 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 2480
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Martin Waller | last post by:
Hello, I'm using the MSXML.XMLHTTP object to obtain the results of an ASP page from an ASP page on the same server. The problem I have is that when the AP refrenced by the XMLHTTP object is run...
6
by: Krzysztof Kubiak | last post by:
I'm trying to make use of XMLHTTP object, but I've come across a problem. It seems that there is no way to create dynamic array of such XMLHTTP objects (to make several requests) and handle them...
3
by: kajol | last post by:
Hi everyone I am trying to get the content of any webpage (URL) using XMLHTTP, and it is working fine for me, but suddenly I have got a URL "http://www.bizrate.com/" which is causing a system...
5
by: bboyle18 | last post by:
Hi, I've been looking into the possibility of using XMLHTTP for my enterprise application but I still have a question. When you send the request to the server, how does the server know how to...
1
by: Kapil Shah | last post by:
Hello everybody, I am trying to develop code to use the correct version of XMLHTTP before using it to send SOAP envelope to WebService . The code I have written is as follows, function...
1
by: Dave H | last post by:
First.. What object (on the client) should I be using these days? var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); or var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); or maybe...
1
by: daninbrum | last post by:
Dear All, Please excuse the following thickness, I am new to client scripting. I have set up a page comprising of three DIVs, the content of which gets changed by XMLHTTP requests (including...
1
by: Andrea Cogliati | last post by:
I'm accessing a Web Service through XMLHttp object from a JavaScript client code. I don't understand how to appropriately handle exceptions from the Web Service. Does anyone have a piece of code...
1
by: mirandacascade | last post by:
I recognize that this question is not about javascript per se...it is more about xmlhttp...posting the question at this site because it appears as though this site has many posts related to xmlhttp...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.