473,322 Members | 1,431 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

XmlHttpRequest & Opera8.00 - Test for setRequestHeader?

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
Jul 23 '05 #1
5 3428
Matt Kruse wrote:
I'd like to test for Opera8.00's missing setRequestHeader
method before actually instantiating the object. ... <snip> 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, ...

<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.
Jul 23 '05 #2
On Mon, 06 Jun 2005 05:13:59 +0200, Matt Kruse <ne********@mattkruse.com>
wrote:
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.
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() ).setRequestHeader ){
// setRequestHeader is supported
}
Is there a preferred way to instantiate an XMLHttpRequest object for IE?


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
http://www.opera.com/
Jul 23 '05 #3

Matt Kruse wrote:
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?


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
http://JavaScript.FAQTs.com/
Jul 23 '05 #4
Martin Honnen wrote:
It depends on what you want to achieve, what features of MSXML you are
looking for.
I'm actually not looking for MSXML features at all, just XMLHHTP (data will
be JSON).
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.


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.XMLHTTP"
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
http://www.JavascriptToolbox.com
Jul 23 '05 #5


Matt Kruse wrote:

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.XMLHTTP"
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.


Microsoft.XMLHTTP 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
http://JavaScript.FAQTs.com/
Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Benedikt Wismans | last post by:
Mozilla/5.0 (X11; U; Linux i686; de-AT; rv:1.7) Gecko/20040630 Dear group, below is a simple XML request. It works fine, the only problem is that Mozilla dos not quit the data transfer mode...
5
by: Jarson | last post by:
My JavaScript is trying to POST data to a CGI script (Perl) using XMLHttpRequest. My CGI server gets different data from IE than Mozilla Firefox. // For Mozilla, req = new XMLHttpRequest(); //...
20
by: chris.schwalm | last post by:
This is part II of this <a...
42
by: Greg | last post by:
Hi, I've designed a bookmark in Ajax / PHP that I will put soon on sourceforge.net. But I've got an very tricky bug. I try it on some computers with Internet Explorer/Windows, Firefox...
1
by: ScriptProblem | last post by:
Hi Guys, I have a security concern with Mozilla and Netscape browsers(In IE it gives secuirity pop window) in Remote server(Client's server).When I am trying to call an Asp.NET web service from...
5
by: Peter Michaux | last post by:
Hi, The FAQ correctly says the following: "Mozilla (NN6.2+, Firefox, Ice Weasle etc), Opera 7.6+, Safari1.2+, the Windows version of IE versions 5+, and some other browsers provide the XML...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.