keithclark / selectivizr

selectivizr is a JavaScript utility that emulates CSS3 pseudo-classes and attribute selectors in Internet Explorer 6-8.
1.71k stars 246 forks source link

getXHRObject throws error in ie8 #9

Closed bendavies closed 13 years ago

bendavies commented 13 years ago

win.XMLHttpRequest throws: Message: Object doesn't support this property or method

Consider testing for ActiveXObject first and falling back to XMLHttpRequest after:

    try {
        return( window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest( ) );
    } catch(e) {
        return null;
    }
keithclark commented 13 years ago

Interesting...

Are you able to recreate this issue in the form of an example I can run in IE8, or detail the steps you went through that resulted in this error?

Testing window.ActiveXObject before XMLHttpRequest doesn't sit well with me as the standards based XHR object is the best of the two options and your suggested method would always defer to ActiveX.

Also, if ActiveX was disabled on your machine then it would fall back to XHR which would still throw an error in your case - although the try/catch would handle that and return null, preventing selectivizr from starting.

keithclark commented 13 years ago

No feedback and unable to recreate - closing

bendavies commented 13 years ago

Keith,

Apologies, just got notification that you replied to this. Strangely I can't replicated this any more either. I thought for a second that it might be IE8's Compatibility mode, but it seems not.

Cheers, Ben

rodamn commented 12 years ago

I am encountering this exact issue on first load of a page. If I refresh, the error goes away.

OS: [On a VM image]: Windows XP Pro SP3 Browser: IE8, DocMode: IE8 Standards

I made a copy of my page and reduced the code to a minimum that repro's the issue:

SEL-TEST-IZR.HTML <!DOCTYPE html> <html> <head> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/mootools/1.3.1/mootools.js"&gt;&lt;/script&gt; <script type="text/javascript" src="scripts/selectivizr.js"></script> <meta charset='UTF-8' /> </head> <body> </body> </html>

The charset meta-tag seems vital to reproducing the issue. Just out of curiosity, I tried toggling IE's page encoding between Western European (default), Auto-Select, and UTF-8, none of which changed the outcome.

Also, the choice of JavaScript libraries does not seem to change the outcome; I personally am using jQuery 1.8.1 and Mootools 1.3.2 (only for nth-child and first-/last-of-type).

TEST SETUP

  1. Client machine (WinXP, IE8) 2a. Prepare web server with an sel-test-izr.html file as described above. 2b. Download selectivizr.js and put in ./scripts/ folder relative to sel-test-izr.html

TEST STEPS

  1. On a client machine, launch IE8
  2. Open IE8 to sel-test-izr.html Test Notes: On successive tests, refreshing the webpage (F5) is insufficient to reproduce this issue. You need to step back in the browser and then point IE8 at sel-test-izr.html (dropdown history box is sufficient to accomplish that).

ACTUAL RESULT Page loads with errors. Double-clicking the error icon in the status bar brings up IE's error window: Object doesn't support this property or method selectivizr.js Line: 378 Code: 0 Char: 4 URI: http://[...]/scripts/selectivizr.js

EXPECTED RESULT Page loads without errors.

atrauzzi commented 11 years ago

I'm encountering this issue as well on the current version of selectivizr. IE8 reports an invalid argument to the open function being called on the XHR.

theprojectsomething commented 10 years ago

We encountered an identical issue today using 1.0.3.b. Attempting to create a new XHR object returns an exception in IE8 (line 384) on initial load or hard refresh.

Our working solution:

if (win.XMLHttpRequest) {
  try {
    return new win.XMLHttpRequest;
  } catch (e) {}
}
try {
  return new ActiveXObject('Microsoft.XMLHTTP');
} catch (e) {
  return null;
}