By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,918 Members | 1,923 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,918 IT Pros & Developers. It's quick & easy.

XMLHttpRequest not working as expected

P: n/a
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,

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Discover Opera: http://members.surfeu.fi/jerkku/
http://www.auriance.com - http://www.auriance.net
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a


Unknown User wrote:
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.respo nseText));
}
};
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.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2

P: n/a
Thanks, it helped!
On Mon, 07 Feb 2005 19:03:39 +0100, Martin Honnen <ma*******@yahoo.de>
wrote:


Unknown User wrote:
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.respo nseText));
}
};
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.


--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Discover Opera: http://members.surfeu.fi/jerkku/
http://www.auriance.com - http://www.auriance.net
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.