Re: History exercise: Mac IE and XMLHttpRequest



On Dec 29, 7:58 pm, Patrick Nolan <p...@xxxxxxxxxxxxxxxxxxx> wrote:
On 2007-12-29, David Mark <dmark.cins...@xxxxxxxxx> wrote:





On Dec 28, 8:52 pm, Patrick Nolan <p...@xxxxxxxxxxxxxxxxxxx> wrote:
I'm working on cross-platform portability of some javascript.
My Macintosh testing platform is rather old.  It has Safari
1.3.2 and Internet Explorer 5.2.  I got Safari working, but
now IE is causing trouble.  It chokes on this:

  if (window.XMLHttpRequest)
      nameReq = new XMLHttpRequest();
  else if (window.ActiveXObject)
      nameReq = new ActiveXObject("Microsoft.XMLHTTP");

The error message on the last line is "Object doesn't support
this action".

Is it possible that this browser is just too old to support
XMLHttpRequest?  If so, does anyone know the earliest version
for which this would work?

It is too old to have XMLHttpRequest and certainly won't create and
ActiveX object.  However, should safely exclude it from using Ajax,
rather than throw an error.  Try this:

else if (typeof window.ActiveXObject == 'function' || (typeof
window.ActiveXObject == 'object' && window.ActiveXObject))

If that fails, do this:

alert(typeof window.ActiveXObject);

(and post the result.)

It says "undefined".  This looks hopeless.  


Not really. Looking at your feature test:


if (window.XMLHttpRequest)
nameReq = new XMLHttpRequest();
else if (window.ActiveXObject)
nameReq = new ActiveXObject("Microsoft.XMLHTTP");

The last line should not execute if window.ActiveXObject is
undefined. Are you sure that is the line that errors?

I seem to remember having some weird problems like this with a very
old Mac AOL browser that was based on IE. Try this cleaned up version
as a test case:

if (typeof window.XMLHttpRequest != 'undefined') {
alert('Creating XMLHttpRequest');
nameReq = new window.XMLHttpRequest();
}
else {
if (typeof window.ActiveXObject != 'undefined') {
alert('Creating ActiveX');
nameReq = new window.ActiveXObject("Microsoft.XMLHTTP");
}
}

You shouldn't get any alerts or errors. If you do get an error, it
should be apparent which line caused it.
.