If you have worked with Prototype and used its really cool Ajax features you might have noticed one downside to it: It will only work in Internet Explorer 6 if ActiveX is enabled. This might seem neglible now that IE7 is spreading - but many businesses and also many other surfers still use IE6 (and will for some time), and for security reasons ActiveX is turned off in many cases. Yet there is a solution to still use Ajax.
When using Ajax for important features on your site, you need it to work reliably all the time for your customers not to complain and be disappointed, so it would be nice to also support IE6 without ActiveX. That way you can rely on Ajax to work everywhere.
I developed an additional class in Javascript to add to Prototype which specifically handles IE6 without ActiveX - it uses an IFrame to make a GET request and otherwise integrates quite seemlessly into Prototype. The downside of this method is it only supports GET requests - no POST requests and no response header settings. This means you must be aware of GET restrictions (max. URL limit of 2083 characters), so very long texts may be cut off at some point, and you must set up your server-side scripts to (also) handle GET requests. But for most uses these restrictions should be manageable.
Integrating the class into Prototype is quite easy - find the following code in prototype.js:
var Ajax = { getTransport: function() { return Try.these( function() {return new XMLHttpRequest()}, function() {return new ActiveXObject('Msxml2.XMLHTTP')}, function() {return new ActiveXObject('Microsoft.XMLHTTP')} ) || false; }, activeRequestCount: 0 }
and replace it with this code:
var Ajax = { getTransport: function() { return Try.these( function() {return new XMLHttpRequest()}, function() {return new ActiveXObject('Msxml2.XMLHTTP')}, function() {return new ActiveXObject('Microsoft.XMLHTTP')}, function() {return new IFrameRequest()} ) || false; }, activeRequestCount: 0 }
All you need except that is the actual IFrameRequest class - here it is:
Not using Prototype?
If you do not use Prototype (although you should) I also made a version which is independent of Prototype - use the class below and treat the IFrameRequest class as you would the XMLHttpRequest object (after instantiating the regular ActiveXObject for IE failed).
View IFrameRequest class which is usable without Prototype
An example in javascript on how to use the class would be something like this:
var xmlobj = new IFrameRequest(); xmlobj.open('GET', 'http://www.incoherent.ch/index.html', true); xmlobj.onreadystatechange = function() { if (this.readyState == 4) { alert('Success!'); /* this.responseText now holds the contents of the request */ } } xmlobj.send();
My name is Andreas Leathley, I am 25 years old and live in Munich, Germany. I spend most of my time developing web projects, especially an online community I'm involved with. 