Jump to content

Not displaying in IE8 and Chrome


knee_boarder

Recommended Posts

The code I've written is working perfectly well in Firefox, Safari and Opera but is not working in IE8 (can't comment on earlier versions as I don't have them) and Chrome.

<script type="text/javascript"><!--if (window.XMLHttpRequest)  {// code for IE7+, Firefox, Chrome, Opera, Safari  xmlhttp=new XMLHttpRequest();  }else  {// code for IE6, IE5  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");  }xmlhttp.open("GET","gallery.xml",false);xmlhttp.send();xmlDoc=xmlhttp.responseXML;var x=xmlDoc.getElementsByTagName("photo");for (i=0;i<x.length;i++)  {  document.write("<div style='float:left;padding:5px;'>");  document.write("<a href='images/gallery/");  document.write(x[i].getElementsByTagName("filename")[0].childNodes[0].nodeValue);  document.write("' target='_blank'><img src='images/gallery/thumbnails/");  document.write(x[i].getElementsByTagName("filename")[0].childNodes[0].nodeValue);  document.write("' alt='");  document.write(x[i].getElementsByTagName("title")[0].childNodes[0].nodeValue);  document.write("' /></a><br />");  document.write("</div>");  //document.write(x[i].getElementsByTagName("title")[0].childNodes[0].nodeValue);    }//--></script>

I thought that the if statement should take care of any browser issues so help would be rather useful!

Link to comment
Share on other sites

Explaining more about the way it's not working would help. Like, are you getting errors that say xmlDoc is not an object? Is the text of the xml file in xmlhttp.responseText? If all that's the case, the browsers may not recognize the mime type of the data. Some code like this before calling your send method might help:

if(xmlhttp.overridemimetype) 	{ 	  xmlhttp.overridemimetype('text/xml'); 	}

I'm a little surprised that you are not testing:1. the value of xmlhttp.status2. that xmlhttp.responseXML is in fact an object (e.g., if (typeof xmlhttp.responseXML != "object") . . .)

Link to comment
Share on other sites

Explaining more about the way it's not working would help. Like, are you getting errors that say xmlDoc is not an object? Is the text of the xml file in xmlhttp.responseText? If all that's the case, the browsers may not recognize the mime type of the data. Some code like this before calling your send method might help:
if(xmlhttp.overridemimetype) 	{ 	  xmlhttp.overridemimetype('text/xml'); 	}

I'm a little surprised that you are not testing:1. the value of xmlhttp.status2. that xmlhttp.responseXML is in fact an object (e.g., if (typeof xmlhttp.responseXML != "object") . . .)

I'll try that when I get back from holiday, the code except from the changes to reflect my own xml file is copied and pasted straight from w3 Schools so I was suprised it wasn't working but I'll do some investigation - thanks very much :)
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...