473,240 Members | 1,544 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,240 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 2472
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 Gtze, 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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.