Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Jan 2009
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    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.

  • Users who have thanked angst for this post:

    scorpius420 (01-27-2009)

  • #3
    New Coder
    Join Date
    Jan 2009
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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!

  • #4
    New Coder
    Join Date
    Jan 2009
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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!!!

  • #5
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    ah nice, a ready state addition to the iframe access would come in handy I'm sure

  • #6
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,292
    Thanks
    10
    Thanked 583 Times in 564 Posts
    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 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #7
    Regular Coder
    Join Date
    Jun 2008
    Location
    SE Wisconsin, US
    Posts
    222
    Thanks
    1
    Thanked 20 Times in 20 Posts
    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.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •