YOUR FEEDBACK
Gregor Rosenauer wrote: well, not what's your take on this? Did I miss a second page of this article or...
AJAXWorld RIA Conference
Early Bird Savings Expire Friday Register Today and SAVE !..

SYS-CON.TV

2008 East
DIAMOND SPONSOR:
Data Direct
Frontiers in Data Access: The Coming Wave in Data Services
PLATINUM SPONSORS:
Red Hat
The Opening of Virtualization
Intel
Virtualization – Path to Predictive Enterprise
Green Hills
IT Security in a Hostile World
JBoss / freedom oss
Practical SOA Approach
GOLD SPONSORS:
Software AG
The Art & Science of SOA: How Governance Enables Adoption
PlateSpin
Effective Planning for Virtual Infrastructure Growth
Fujitsu
Automated Business Process Discovery & Virtualization Service
Ceedo
Workspace Virtualization
Click For 2007 West
Event Webcasts

2008 East
PLATINUM SPONSORS:
Appcelerator
Think Fast: Accelerate AJAX Development with Appcelerator
GOLD SPONSORS:
DreamFace Interactive
The Ultimate Framework for Creating Personalized Web 2.0 Mashups
ICEsoft
AJAX and Social Computing for the Enterprise
Kaazing
Enterprise Comet: Real–Time, Real–Time, or Real–Time Web 2.0?
Nexaweb
Now Playing: Desktop Apps in the Browser!
Sun
jMaki as an AJAX Mashup Framework
POWER PANELS:
The Business Value
of RIAs
What Lies Beyond AJAX?
KEYNOTES:
Douglas Crockford
Can We Fix the Web?
Anthony Franco
2008: The Year of the RIA
Click For 2007 Event Webcasts
TOP THREE LINKS YOU MUST CLICK ON


AJAX: XMLHttpRequest Vs. iFrames
XMLHttpRequest Vs. iFrames

Should you use the old iFrame tricks or the new XMLHttpRequest? There is not better or worse when comparing these two techniques, but they are certainly different. While both of them allow you to communicate with the server in the background, you should choose the appropriate for your situation depending on a few questions: Do you want the back-forward buttons to work? Do you plan to perform more than one simultaneous request? Do you need cross-site calls? Do you need to monitor the status of your calls?

I'm pretty sure there are more differences, and way around the ones I will mention for either technique, but out of the box, here are the differences:

                            XHR           iFrame
Multithread:       yes             no
Back button      no               yes
Cross-site        no               yes
Statuses           yes             no

Some people use iframes because it's easier to monitor… all you have to do is to show the hidden iframe and voila, you see the responses. On the other hand, I use several http traffic sniffers that give me even more accurate information, and they're extremely easy to use. So that's not a plus for me.

Multithread is huge... you could achieve this with iframes if you create a framework that will create a new iframe using dom, use it for the call and delete it once it's completed. When using XHR, you can easily create a new remote request with simple scripting.

The back button breaks by default when using XHR. Sometimes it is actually good, f.e, if I populate a city and state using a zip code, or check if an email has been taken prior to submitting a form I wouldn't like to add a history step, so I'm glad the back button doesn't recognize that request. There are ways around it too if you do need it to work. I will post some solutions/possibilities soon.

Cross-site scripting ... while you would like this to work to use web services, they do not really work with iframes either. When scripting with iframe you need to explicitly call a function in the parent or top window, so unless you control both sites, this advantage is useless. You can implement a server side web service proxy relatively easy and I would suggest doing that if you need to use WS.

Finally, statuses... with an iframe you do not know in that status your call is. With XHR you have 5 different ones: 0 = uninitialized, 1 = loading, 2 = loaded, 3 = interactive, 4 = complete. They are useful to provide the user with more accurate information.

In conclusion, most of the times XHR is preferable over iframes, but there are cases and cases. Google maps uses iframes, while google suggest uses XHR.

This article was republished with permission of the Author.

About Rob Gonda
Rob Gonda is the CTO for iChameleon Group and Contributing Editor to AJAXWorld Magazine. He is an Advanced Certified Coldfusion Developer, member of the Adobe Community Experts, frequent contributor to the CFDJ and ADJ, frequent speaker at IT and developer conferences nationwide, co-author of Real-World Ajax Book, author of ajaxCFC, holds a BS in computer science and engineering, an MBA with a specialization in entrepreneurship, and he specializes in Rich Internet Applications and object-oriented architecture. You can reach him at rob[at]robgonda[dot]com and read his blog is at http://www.robgonda.com

YOUR FEEDBACK
Kenneth wrote: You forgot to mention a disadvantage of xmlHttpRequest that is a major issue for me: You can't(at least not directly) run scripts that are returned as part of the response.
David wrote: I can not read your story. Your ads are too intrusive. Bye
Ajax News Desk wrote: Should you use the old iFrame tricks or the new XMLHttpRequest? There is not better or worse when comparing these two techniques, but they are certainly different. While both of them allow you to communicate with the server in the background, you should choose the appropriate for your situation.
LATEST AJAXWORLD RIA STORIES
JavaScript 2 is becoming increasingly important. Learn how to take advantage of JavaScript 2 while still running in today's browsers. Leverage your current JavaScript and HTML skills to build applications that run in Flash 7-9, DHTML and more with no code changes! OpenLaszlo 4.2 ...
Enterprises are enthusiastically embracing the shift from traditional client/server computing to SaaS. Inspired by customers who have embraced the web, developers are using RIA tools to create innovative new on-demand business applications. One important factor in the shift from ...
RIAs provide the promise of an excellent User experience, but the ultimate success of the UX is driven more by the skill of the developer than the tool selection itself. This session will discuss the foundation and importance of the application of cognitive science techniques to ...
Rich Internet Applications have become ubiquitous to the point that many of us rely on them for daily activities. But there's a big difference between consumer websites and enterprise-class applications. While new browser capabilities provide a richer look and feel for consumer s...
Cloud Computing isn’t just another buzzword: this session will look at what the industry is up to, Amazon is up to, and especially how people are innovating in the cloud. Buzzwords aside, virtualized (cloud) computing is a disruptive game changer at both technical and business ...
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS
SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021


SYS-CON FEATURED WHITEPAPERS

ADS BY GOOGLE