Internet Explorer (IE) and responseText

Playing a bit on job with xmlhttprequest (more or less on December 2006), I bumped into another IE6 bug (?). I needed to parse an xml stream like the following





<MSG><COD>-1</COD><DESC>blablal</DESC></MSG>

yes, with some empty lines before the XML stream. The problems was that empty lines before the xml stream. While Firefox handled them correctly (ignoring), IE6 hanged up silently (as usual) , so no error displayed. Solved in this way

xmlhttp.onreadystatechange = function(){
   if(xmlhttp.readyState==4){
      if(window.ActiveXObject){
         result = new ActiveXObject("Microsoft.XMLDOM");
         result.async="false";
         result.loadXML(xmlhttp.responseText);
      }else{
         result = xmlhttp.responseXML;
      }
      cod = result.getElementsByTagName("COD")[0].firstChild.data;
      if(cod!="0"){
         desc = result.getElementsByTagName("DESC")[0].firstChild.data;
         alert("Error while... nn" + desc);
      }else{
         alert("Operation successful");
      }
      ...
   }
};

Ah yes , remember the content-type="text/xml"; charset=...

Advertisements

2 thoughts on “Internet Explorer (IE) and responseText

  1. gregoire says:

    Thank but if i may add a thing,
    the XML nodes of the ajax xml file are in xmlhttp.documentElement
    so the result contain not the same thing on ie and ff/op/saf ; it should be

    if(window.ActiveXObject){
    doc = new ActiveXObject(“Microsoft.XMLDOM”);
    doc.async=”false”;
    doc.loadXML(xmlhttp.responseText);
    var result = doc.documentElement
    }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s