AJAX on IE - back to the IFRAME
By Pete Freitag
On Internet Explorer in order to write AJAX based web applications you have to use an ActiveX object.
var request = new ActiveXObject("Microsoft.XMLHTTP");
On browsers that support the XMLHttpRequest object (Safari, Firefox) you instantiate your asynchronous http object as follows:
var request = new XMLHttpRequest();
Most AJAX apps have a browser check to determine which one to use.
Kae Verens recently pointed out in a blog entry that web sites that use AJAX won't work on IE when ActiveX controls are disabled in the security settings.
This is an important point to ponder when considering AJAX for a web application. Lots of companies will have ActiveX controls disabled, and keep in mind that IE is still the most popular web browser.
So how do you fix this? Back to using hidden IFRAME
tags, which I have always thought worked just fine. Kae, has actually written some javascript to do this in his article.
I have actually looked around for some discussion on IFRAMEs vs XMLHttpRequest (aka AJAX), but haven't found much. There are a few nice features of the XMLHttpRequest object, those mostly deal with access to headers, status codes, and other http details. Which is nice but you don't always need that info.
Are there any other advantages to using XMLHttpRequest objects over IFRAMEs?
AJAX on IE - back to the IFRAME was first published on August 17, 2005.
If you like reading about activex, ajax, ie, iframe, firefox, xmlhttprequest, or javascript then you might also like:
- Ajax Same Origin Policy No More with Firefox 3.5
- Firefox Now Supports HttpOnly Cookies
- AJAX Presentation Outline
- One liner to download a Browser with PowerShell on Windows Server
Discuss / Follow me on Twitter ↯
Tweet Follow @pfreitagComments
It's from way back (january 2002), but it's still valuable. One of the drawbacks of iframes would be the browser refresh/back buttons, as the article points out (and then also tries to solve).
but that's just me.
iframe's can be a pain in the ass, to code and to style properly in the page -- esp. getting it to look proper or the same across all the major browsers... least, that's what i've found ;)
I don't understand why IFrame style comes into it at all, either. If you'd read the source of what I wrote, you'd see that the IFrame is never actually displayed on the page.
And - across all the major browsers?? This code is to solve a problem /specifically/ in IE - no cross-browser support needed!
http://verens.com/demos/Sajax.phps
There is an open source php/javascript library, using a hidden iframe to perform database/server requests without refreshing the page, at
http://simpletutorials.com/tutorials/jsrs/index.php
I've found it pretty simple to use.
But it's also the little things about xmlHttpRequest that give it an edge over iFrames. Like the "clean" way to create/distroy "loading" flags. With the readystatechange property of xmlHTTP you can create a flag on "state 1" and destroy it on "state 4".
Randomly the requestor will quit immediately claiming an error status 12029, 12030, 12152, 12159 and a couple others. I'm racking my brains over a way to reliably code around this and would love suggestions from anyone that has had this experience and solved it. Perhaps it's fixed in Msxml2.XMLHTTP.6.0 - but it will be a while before everyone is there...
The problem for me is on the send, not the response - are you saying that this is actually an unclosed PREVIOUS connection and that fixed it? I'll have to try that, but would love more details from you
I have a one ajax file and one calling file to ajax I have some error on IE browser only one time. when first time load page on ie browser create error and second time remove them please suggest what is problem in ajax return file code