I recently did a lot of investigating around the best way to create an XMLHttpRequest, as various resources on the web use slightly different methods. Newer browsers (Chrome, Firefox, IE7+, Opera, and Safari) all have a native XMLHttpRequest object, so the exception is really IE versions less than 7.
Internet Explorer 5, 5.5, and 6 all support XMLHttpRequest by means of an ActiveXObject. But there are various versions of MSXML, and it was not clear to me which versions should be used, and in which order they should be declared. Microsoft recommended some versions, but their recommendation was 3 years old and I wasn’t sure if it was still applicable (or applicable at all when using MSXML for creating XMLHTTP objects). It turns out that it was.
Initially I wanted to support the widest range of browsers, including IE5 and IE5.5. However, those versions of IE are no longer supported by Microsoft, so why should I try and support them? I have no way to test in those versions. More research suggested that IE5 and IE5.5 account for only about .02% of browser market share (2 people out of 10,000) from August 2009 – October 2009. It doesn’t make sense to try and support IE5.x, which means there is no need to support the legacy Microsoft.XMLHTTP ActiveXObject.
That just leaves IE6. IE6 still has considerable market share, so I do want to support it. IE6 shipped with MSXML 3.0, which is the “fallback” version to use recommended by Microsoft. Previous versions of MSXML are no longer supported by Microsoft, so MSXML 3.0 will be my fallback version. The recommended version is MSXML 6.0 (note, it is NOT recommended to use MSXML 5.0 or MSXML 4.0).
So now I’m going to be working with a set of 3 possible objects:
- a native XMLHttpRequest object
- an MSXML 6.0 XMLHTTP ActiveXObject (IE6 only)
- an MSXML 3.0 XMLHTTP ActiveXObject (IE6 only, when MSXML 6.0 not available)
To see how I decided to format that code, visit: