I'd like to test for Opera8.00's missing setRequestHeader method before
actually instantiating the object. For example, this works in firefox:
if (XMLHttpRequest.prototype.getRequestHeader) { ... }
It causes an error in Opera8.00. In fact, doing
typeof(XMLHttpRequest.prototype) returns 'undefined' in Opera8.00. I'm not
sure how Opera is actually implementing the XMLHttpRequest object, but I
suppose it's not a native object that can be examined? If I instantiate an
object, I can test just fine:
var x = new XMLHttpRequest();
if (x.setRequestHeader) { ... }
But before I get to the point of instantiating, I'd like to detect whether
submitting my POST form is going to work at all, so I can bomb out if it
won't be supported. Is there a better way to test?
Also, while I'm here...
Is there a preferred way to instantiate an XMLHttpRequest object for IE?
I've seen all kinds of different approaches. Some try a long list of ActiveX
components, some just instantiate XMLHTTP, some Microsoft.XMLHTTP, some
Msxml2.XMLHTTP, etc. Many use try/catch which will break older browsers. Is
there a proven method which degrades nicely and will work consistently with
IE?
--
Matt Kruse
http://www.JavascriptToolbox.com