XmlHttpRequest & Opera8.00 - Test for setRequestHeader?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Matt Kruse

    XmlHttpRequest & Opera8.00 - Test for setRequestHeader?

    I'd like to test for Opera8.00's missing setRequestHeade r method before
    actually instantiating the object. For example, this works in firefox:

    if (XMLHttpRequest .prototype.getR equestHeader) { ... }

    It causes an error in Opera8.00. In fact, doing
    typeof(XMLHttpR equest.prototyp e) 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.setRequestHe ader) { ... }

    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.XMLHT TP, 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



  • Richard Cornford

    #2
    Re: XmlHttpRequest & Opera8.00 - Test for setRequestHeade r?

    Matt Kruse wrote:[color=blue]
    > I'd like to test for Opera8.00's missing setRequestHeade r
    > method before actually instantiating the object. ...[/color]
    <snip>[color=blue]
    > 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, ...[/color]
    <snip>

    There is no point trying this as you cannot determine the viability of
    XMLHttpRequests on IE without instantiating the object (or at least
    trying to, as failure to instantiated is the indicator of
    non-viability).

    Richard.


    Comment

    • Hallvord R. M. Steen

      #3
      Re: XmlHttpRequest &amp; Opera8.00 - Test for setRequestHeade r?

      On Mon, 06 Jun 2005 05:13:59 +0200, Matt Kruse <newsgroups@mat tkruse.com>
      wrote:
      [color=blue]
      > I'd like to test for Opera8.00's missing setRequestHeade r method before
      > actually instantiating the object. For example, this works in firefox:
      >
      > if (XMLHttpRequest .prototype.getR equestHeader) { ... }
      >
      > It causes an error in Opera8.00. In fact, doing
      > typeof(XMLHttpR equest.prototyp e) returns 'undefined' in Opera8.00.[/color]

      Correct, the XMLHttpRequest object does not have a prototype - Opera does
      not (yet?) support extending it through the prototype syntax.

      Try this approach:

      if( ( new XMLHttpRequest( ) ).setRequestHea der ){
      // setRequestHeade r is supported
      }
      [color=blue]
      > Is there a preferred way to instantiate an XMLHttpRequest object for IE?[/color]

      No idea. The scripts I've seen that seem most thoroughly tested do rely on
      a list of identifiers and try...catch, so I'd assume that is the best
      approach.
      --
      Hallvord R. M. Steen
      Opera Software
      Faster, safer and smarter than default browsers. Fully-featured for privacy, security, and so much more. Get the faster, better Opera browser for free.

      Comment

      • Martin Honnen

        #4
        Re: XmlHttpRequest &amp; Opera8.00 - Test for setRequestHeade r?


        Matt Kruse wrote:
        [color=blue]
        > 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.XMLHT TP, 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?[/color]

        It depends on what you want to achieve, what features of MSXML you are
        looking for. For instance if you are going to load an XML document and
        and XSLT stylesheet to perform an XSLT 1.0 transformation then you need
        at least MSXML 3 which has the version dependent program id
        Msxml2.XMLHTTP. 3.0
        so in that case it might make sense to try to instantiate that
        particular version dependent program id or in case you want to exploit
        better XSLT performance in later MSXML versions you might even want to
        try to instantiate higher versions to use the highgest version available.

        As for try/catch you can use conditional comments to avoid problems with
        older browsers.

        See also
        <http://www.faqts.com/knowledge_base/view.phtml/aid/35742/fid/616>
        which tries to be some guidance on the use of programming ids.

        --

        Martin Honnen

        Comment

        • Matt Kruse

          #5
          Re: XmlHttpRequest &amp; Opera8.00 - Test for setRequestHeade r?

          Martin Honnen wrote:[color=blue]
          > It depends on what you want to achieve, what features of MSXML you are
          > looking for.[/color]

          I'm actually not looking for MSXML features at all, just XMLHHTP (data will
          be JSON).
          [color=blue]
          > See also
          > <http://www.faqts.com/knowledge_base/view.phtml/aid/35742/fid/616>
          > which tries to be some guidance on the use of programming ids.[/color]

          I did see this in my pre-post research. This in particular made me wonder:

          :Note that from MSXML 4 on there are only version dependent program ids
          :so that the earlier version independent program ids are never bound to
          :MSXML 4 or 5.

          Does the same apply to XMLHTTP? If I just instantiate "Microsoft.XMLH TTP"
          will I always get the latest version? Or will it only link to older
          versions? I want to always get the latest and greatest that is on the
          machine, which would presumably be more efficient and stable and bug-free.
          But I also don't want to update my script every time a new version is
          released so I can check for it also.

          --
          Matt Kruse



          Comment

          • Martin Honnen

            #6
            Re: XmlHttpRequest &amp; Opera8.00 - Test for setRequestHeade r?



            Matt Kruse wrote:

            [color=blue]
            > This in particular made me wonder:
            >
            > :Note that from MSXML 4 on there are only version dependent program ids
            > :so that the earlier version independent program ids are never bound to
            > :MSXML 4 or 5.
            >
            > Does the same apply to XMLHTTP? If I just instantiate "Microsoft.XMLH TTP"
            > will I always get the latest version? Or will it only link to older
            > versions? I want to always get the latest and greatest that is on the
            > machine, which would presumably be more efficient and stable and bug-free.[/color]

            Microsoft.XMLHT TP is a version independent program id which is never
            bound to MSXML 4 or later. MSXML 3 is the last version that can be (and
            usually is) installed in so called replace mode (meaning it replaces
            earlier versions and binds itself to the version independent ids), if
            you want to use MSXML 4 or later you need to use version dependent ids
            (e.g. new ActiveXObject(' Msxml2.XMLHTTP. 4.0') for the XMLHTTP request
            object of MSXML 4). So there is no way to use one general version
            independent program id and ensure that the latest MSXML version is used,
            if you really expect MSXML 4 or later on the client then you have to use
            a version dependent program id respectively try to instantiate certain
            versions to find the latest installed version.


            --

            Martin Honnen

            Comment

            Working...