XMLHttpRequest not working as expected

U

Unknown User

I am trying to implement XMLHttpRequest to a new website, but when I
include HTML, the code appears as is, instead of the formated HTML. Please
have a look and click the 1st link ("L'Association") on top (yello
horizontal bar on top): http://www.auriance.com/docs/alcan/index.php
How can I fix it?
Thanks,
 
M

Martin Honnen

Unknown said:
I am trying to implement XMLHttpRequest to a new website, but when I
include HTML, the code appears as is, instead of the formated HTML.
Please have a look and click the 1st link ("L'Association") on top
(yello horizontal bar on top):
http://www.auriance.com/docs/alcan/index.php
How can I fix it?

Not sure what you complain about, you have

function loadcode(File, Dest) {
var req = new XMLHttpRequest();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4 && req.status == 200) {
removecode(Dest);
var demo = document.getElementById(Dest);
demo.appendChild(document.createTextNode(req.responseText));
}
};
req.open('GET', File);
req.send(null);
}
}

so you simply make a text node with the complete responseText and then
insert that into the document, that is why you see the source you fetch.
If you want to use responseText then you should set
demo.innerHTML = req.responseText;
but at least in Mozilla that is going to present problems as your page
is served as application/xhtml+xml and innerHTML setting doesn't work
there. But of course with Mozilla you could fetch XHTML (make sure you
have the proper namespace on the elements then e.g.
<div xmlns="http://www.w3.org/1999/xhtml">...</div>
and then you can use responseXML and use importNode to copy the nodes
into the existing document.
For IE however you need another strategy.
And that JavaScript file your page includes also seems to try to use
Java via LiveConnect for Opera, I haven't looked close enough to tell
you whether that emulation gives you more than responseText and how to
use it, ask the author of that stuff.
 
U

Unknown User

Thanks, it helped!


Not sure what you complain about, you have

function loadcode(File, Dest) {
var req = new XMLHttpRequest();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4 && req.status == 200) {
removecode(Dest);
var demo = document.getElementById(Dest);
demo.appendChild(document.createTextNode(req.responseText));
}
};
req.open('GET', File);
req.send(null);
}
}

so you simply make a text node with the complete responseText and then
insert that into the document, that is why you see the source you fetch.
If you want to use responseText then you should set
demo.innerHTML = req.responseText;
but at least in Mozilla that is going to present problems as your page
is served as application/xhtml+xml and innerHTML setting doesn't work
there. But of course with Mozilla you could fetch XHTML (make sure you
have the proper namespace on the elements then e.g.
<div xmlns="http://www.w3.org/1999/xhtml">...</div>
and then you can use responseXML and use importNode to copy the nodes
into the existing document.
For IE however you need another strategy.
And that JavaScript file your page includes also seems to try to use
Java via LiveConnect for Opera, I haven't looked close enough to tell
you whether that emulation gives you more than responseText and how to
use it, ask the author of that stuff.
 

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,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top