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;
}
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;
}