« AJAX in Action Reviewed | Main | Zimbra ALE, Ajax Linking and Embedding »

AJAX XMLHttpRequest x IFrame

A new version of PHPClasses 2.0 Beta is being under tests, introducing new features and services for premium subscribers, you can check already the new AJAX Login page of the service. Manuel posted an interested comparaison between AJAX XMLHttpRequest x IFrame, explaining the reasons why he choosed IFrame versus XMLHttpRequest.

What I would like to share with you are the reasons why I have chosen IFrame over XMLHttpRequest objects.

Since Mozilla 1.0 release, there is a lot of excitement in the Web development community regarding the use of XMLHttpRequest objects to implement AJAX enhanced applications.

However, after some preliminary studies, I have reached the conclusion that using IFrame is much better than using XMLHttpRequest objects.

These reasons are :

1- Browser compatibility : IFrame is widely suuported by new and old browsers while not all browsers in use support XMLHttpRequest

2- Browser security constraints : Under Internet Explorer 6, XMLHttpRequest requires an ActiveX component. The latest Microsoft security patches disable ActiveX by default. XMLHttpRequest is not available under the default security level of installations that use that security patch.

3- Single JavaScript base code : Several browsers now support XMLHttpRequest but each one has a different way to create these objects and access them. This causes a maintenance headache because you need to generate browser specific JavaScript code. IFrame is an HTML tag consistently supported across all modern browsers. A single JavaScript base code works with all supported browsers.

4- Response speed : tests have proven that XMLHttpRequest can be faster for small requests but IFrame can be faster for larger requests.

5- File form upload : With IFrame there is no need to access the actual form file input values. You just use the IFrame name to set the target of the form with the file input that you want to upload. When the form is submitted the file is uploaded with all other fields of the form. While due to security reasons you cannot access the value of form file inputs to populate an XMLHttpRequest.

Bookmark this article at these sites
Comments
1

No Comments

2

excellent

3

Another two points, also tipping in favour of iframes:
1. With an iframe you automatically get the values of every field on the form in server side script, but with XHR you have to manually loop through all the form fields, get each value, url encode them and append to a query string
2. The output of the response in an iframe is html, which can contain script. This is useful if you are wanting to change out some complex or long html content and/or execute some possibly long or complex script. With XHR you have to decide what format to use (eg json or xml), encode your response properly and then parse it on the client, which is harder to read and debug.

Post a comment





(Email will remain hidden)





Please enter the security code you see here




Related entries
Email to a friend
Email this article to:


Your email address:


Message (optional):