Over a million developers have joined DZone.

XMLHttpRequest Calls in IE 9 Standards Mode

· Web Dev Zone

Learn why developers are gravitating towards Node and its ability to retain and leverage the skills of JavaScript developers and the ability to deliver projects faster than other languages can.  Brought to you in partnership with IBM.

With all versions of Internet Explorer, even when IE becomes more standards compliant, there are usually workarounds that are still needed.

Even though IE 9 is the most standards compliant Microsoft browser to date, there are still several things that have been discovered that we need to be aware of.

Feature detection tests should always test for W3C features first and fall back to IE specific features if the W3C feature is unavailable. For example, the following would be the feature detection code to use to create an XML object from a string of XML:

function ConvertStringToXMLObject(sXML) {
     // Test for W3C feature
     if (DOMParser) {
          var dpDOMParser = new DOMParser();
          return dpDOMParser.parseFromString(sXML, "text/xml");
     } else { // IE 8 and previous or IE 9 when *not* in Standards mode...
          var xdDoc = new ActiveXObject("Microsoft.XMLDOM");
          xdDoc.loadXML(sXML);
          return xdDoc;
     }
} 

When Standards mode is on, IE 9 now supports the DOMParser object. The issue with this, however, is that the XMLHttpRequest object still returns an MSXML ActiveX object from the reponseXML property no matter which document compatibility mode IE 9 is using.

The MSXML ActiveX XML object is not compatible with the DOMParser XML object and will result in a 'Type mismatch' error if you try to append the one XML object to the other.

The workaround for this issue is to pass the responseText property, from your XMLHttpRequest object, to your client-side XML object creation function so that you get an XML object of the proper type as in the following example: 

function MakeServerSideCall(sURL, sPostData) {
     var xhrRequest = GetXMLHttpRequestObject();
     xhrRequest.open("POST", sURL, false);
     xhrRequest.send(sPostData);

     return ConvertStringToXMLObject(xhrRequest.responseText);
} 

The following is a Microsoft article which talks about the DOMParser object, XMLSerializer object, as well as this workaround for the XMLHttpRequest object: http://blogs.msdn.com/b/ie/archive/2010/10/15/domparser-and-xmlserializer-in-ie9-beta.aspx 

 

Source: http://cggallant.blogspot.com/2011/03/xmlhttprequest-calls-when-in-ie-9.html

Make the transition to Node.js if you are Java, PHP, Rails or .NET developer with these resources to help jumpstart your Node.js knowledge plus pick up some development tips.  Brought to you in partnership with IBM.

Topics:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}