Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-27-2009, 04:12 PM   PM User | #1
scorpius420
New Coder

 
Join Date: Jan 2009
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
scorpius420 is an unknown quantity at this point
Smile Why use AJAX instead of iframes?

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.
scorpius420 is offline   Reply With Quote
Old 01-27-2009, 04:19 PM   PM User | #2
angst
Senior Coder

 
angst's Avatar
 
Join Date: Apr 2004
Location: Toronto, Ontario
Posts: 2,112
Thanks: 15
Thanked 122 Times in 122 Posts
angst is on a distinguished road
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.
angst is offline   Reply With Quote
Users who have thanked angst for this post:
scorpius420 (01-27-2009)
Old 01-27-2009, 06:03 PM   PM User | #3
scorpius420
New Coder

 
Join Date: Jan 2009
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
scorpius420 is an unknown quantity at this point
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 is offline   Reply With Quote
Old 01-27-2009, 06:38 PM   PM User | #4
scorpius420
New Coder

 
Join Date: Jan 2009
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
scorpius420 is an unknown quantity at this point
Cool yes you can!!

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!!!
scorpius420 is offline   Reply With Quote
Old 01-27-2009, 06:42 PM   PM User | #5
angst
Senior Coder

 
angst's Avatar
 
Join Date: Apr 2004
Location: Toronto, Ontario
Posts: 2,112
Thanks: 15
Thanked 122 Times in 122 Posts
angst is on a distinguished road
ah nice, a ready state addition to the iframe access would come in handy I'm sure
angst is offline   Reply With Quote
Old 01-27-2009, 07:00 PM   PM User | #6
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,468
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
Quote:
Originally Posted by scorpius420 View Post
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...
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
rnd me is offline   Reply With Quote
Old 01-28-2009, 03:25 AM   PM User | #7
demtron
Regular Coder

 
Join Date: Jun 2008
Location: SE Wisconsin, US
Posts: 222
Thanks: 1
Thanked 20 Times in 20 Posts
demtron is on a distinguished road
Ajax can be significantly more lightweight in its communications when requesting/receiving data.
__________________
Milwaukee Web Designer and SEO Milwaukee Firm specializing in ASP.Net, C#, VB.Net, SQL Server and Access.
demtron is offline   Reply With Quote
Reply

Bookmarks

Tags
ajax, callback, html, iframe, request

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:32 AM.


Advertisement
Log in to turn off these ads.