...

View Full Version : Why use AJAX instead of iframes?



scorpius420
01-27-2009, 05:12 PM
Can't you do everything you can do with AJAX using iframes by simply setting the src attrib and passing parameters as a GET query string?

P.S. Is there anything iframes can do that AJAX and a a <div> or a <span> can't do?

Thanks.:)

angst
01-27-2009, 05:19 PM
it's not the same thing.
Ajax is to run querys/post data and so on in the background and return the results directly to the currently loaded page, ie: without more page reloading.

iframe is just a normal web page loading into a frame.

scorpius420
01-27-2009, 07:03 PM
yeah but you just change the src, add parameters as a get query string, and you can have a hidden collpased iframe for pure data requests where you don't want to show the returned text... IF you could access what was inside your iframe...

which after some searching and experimentation, leads to an access denied message...

hmm...ok, it doesn't work due to security protocols... answered me own question then...

thanks!

scorpius420
01-27-2009, 07:38 PM
bit of research shows there is some new DOM syntax for easy access to what is inside your iframe:

document.getElementById(iframeId).contentDocument

and yuo just have to check if the readystate property is set to "complete" to make sure everything is downloaded.

This may not work across domains and security barriers, but for accessing data and content fromy our own site, it does.

A hidden collapsed iframe in such instances is an easy alternative to AJAX. I've tested it. it works!!! :thumbsup:

angst
01-27-2009, 07:42 PM
ah nice, a ready state addition to the iframe access would come in handy I'm sure

rnd me
01-27-2009, 08:00 PM
Can't you do everything you can do with AJAX using iframes by simply setting the src attrib and passing parameters as a GET query string?

P.S. Is there anything iframes can do that AJAX and a a <div> or a <span> can't do?

Thanks.:)

iframes can make requests to other domains and sites, ajax cannot.

ajax can update the page contents in shapes other than a rectangle...

demtron
01-28-2009, 04:25 AM
Ajax can be significantly more lightweight in its communications when requesting/receiving data.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum