XMLHttpRequest, Firefox and IE inconsistent

R

Rich Hephner

I'm a rookie to XMLHttpRequest and I'm having a hard time creating an
XML object that I can parse using both IE and FireFox. Works great in
Firefox, but IE returns "0" for "alert(topics.length)".
What am I doing wrong? Does IE not recognize responseXML? Thanks.
Here's my code:

function initialize(){
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();
}
xmlhttp.open("GET", "test.xml",true);
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
alert(xmlhttp);
var topics = xmlhttp.responseXML.getElementsByTagName("topic");
alert(topics.length);
for(i=0;i<topics.length;i++){
name += topics.getAttribute("name") + "\n";
}
alert(name);
}
}
xmlhttp.send(null)
}

if(document.getElementById && document.createTextNode){
window.onload = initialize;
}
 
P

phil_gg04

I'm a rookie to XMLHttpRequest and I'm having a hard time creating an
XML object that I can parse using both IE and FireFox

I'm going to sound like a record stuck in a groove because I said
exactly this to the last person with an XmlHttpRequest problem: use the
Sarissa library (google for it). It does an excellent job of hiding
the browser differences.

--Phil.
 
R

Rich Hephner

Thanks for the replies. I had considered Sarissa, but I'm a stubborn
programmer who doesn't beleive in using code from someone else when you
can write it yourself. : )

As simple a task as this SHOULD be, it isn't turning out that way, so i
may go the Sarissa route after all. Thanks again.
 

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

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top