PHP Classes


Recommend this page to a friend!

      PHP Classes blog  >  PHPClasses 2.0 Beta, ...  >  All threads  >  AJAX with IFRAME  >  (Un) Subscribe thread alerts  
Subject:AJAX with IFRAME
Summary:We have been using IFRAMES for AJAX for 5 years, except...
Author:David Ethell
Date:2006-03-31 15:10:59
Update:2006-07-03 13:15:23

  1. AJAX with IFRAME   Reply   Report abuse  
Picture of David Ethell David Ethell - 2006-03-31 15:13:02
The only downside of using IFRAME for AJAX is that Internet Explorer makes an annoying "click" sound when opening a new page. This can be disabled in the browser, but not programatically, so visitors to our AJAX-with-IFRAME pages here a click every time the IFRAME refreshes.

Despite that limitation, however, we love using IFRAMES instead. For all the reasons you mentioned such as executing JavaScript before the load is complete, for file uploads, for simpler data handling (Javascript arrays are returned instead of XML documents that must be parsed) it has always seemed better to use IFRAMES.

We even built a web-based IM client using IFRAMES instead of XMLHttpRequest object because the IE browsers at this particular client would crash any time the XMLHttpRequest object was loaded even though their version of IE supported it and ActiveX was turned on.

-David Ethell

  2. Re: AJAX with IFRAME   Reply   Report abuse  
Picture of Guilherme Blanco Guilherme Blanco - 2006-03-31 16:54:06 - In reply to message 1 from David Ethell
Instead of stay sending requests to IFrame sequentially, you use a technique that you can send only one request and use it during until 20 minutes (Apache default timeout limit).

All you have to do is to make a while counting the time and make a sleep at the end of each request.

This solves the "tic" problems for at least 20 minutes... not one "tic" at each 20 minutes isn't so anoying... =)


  3. Re: AJAX with IFRAME   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2006-03-31 17:29:36 - In reply to message 1 from David Ethell
I was just discussing the click problem with Guilherme on the other day.

Depending on how you implement it, this is a legitimate concern, because you may really annoy the users with excessive click sounds.

Guilherme presented an example of a chat system or another kind of application that needs to regularly poll the server for any updates.

However, as I mentioned, you need to realize that unlike XMLHttpRequest, an IFrame response page may contain multiple segments of JavaScript code that can perform updates to the browser pages at any moment with a single request.

This means that you can use a single IFrame request to receive updates from the server. The HTTP connection could be kept open forever if you want, so you can receive JavaScript code updates immediately after the server is ready, as long as it does not exceed the Apache 20 minutes timeout between two updates without sending data.

This way, you would hear only one click.

  4. Re: AJAX with IFRAME   Reply   Report abuse  
Picture of Ari Bjarnason Ari Bjarnason - 2006-04-02 23:18:07 - In reply to message 3 from Manuel Lemos
And you do not have the same back button problem when using a Iframe.

  5. Re: AJAX with IFRAME   Reply   Report abuse  
Picture of Swen Horvath Swen Horvath - 2006-07-03 13:06:17 - In reply to message 2 from Guilherme Blanco
Am my missing something here ? As far as i know most PHP installations will terminate script execution after 30 seconds. So how can one keep a http connection alive 20 minutes if the server feedback terminates befor that ?

  6. Re: AJAX with IFRAME   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2006-07-03 13:15:23 - In reply to message 5 from Swen Horvath
If you set PHP time limit to 0, PHP will not halt the script at all.