Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Need to load External page inside of #myelement

  1. #1
    Join Date
    Jan 2009
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Need to load External page inside of #myelement


    Hi I need to call another page and display it in a <div>
    using jQuery with no onclick functions or anything
    just when the page loads display another page inside #mybox
    this should be a very small code i am sure but after reading all of the documentation
    everywhere i still can't get it to work so i am using an <iframe>.
    Thanks...FacoT...
    Last edited by FacoT; 01-17-2009 at 08:13 AM.

  2. #2
    Join Date
    Jan 2009
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    So far I know this much
    but it is not helping me

    /*.............................................................
    <script type=text/javascript>

    $.ajax({
    type: ?text/html?
    url: "myPage.html",
    data: {name : ?html ? },
    success: function( ?display? ?.append ? ){
    alert( " ?hey i dont want any alert? ");
    }
    });

    </script>
    ..............................................................*/

  3. #3
    Join Date
    Jan 2009
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Need to load External page inside of #myelement

    Need to load External page inside of #myelement

    Hi I need to call another page and display it in a <div>
    using jQuery with no onclick functions or anything
    just when the page loads display another page inside #mybox
    this should be a very small code i am sure but after reading all of the documentation
    everywhere i still can't get it to work so i am using an <iframe>.
    Thanks...FacoT...

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
    <script type="text/javascript">
    $(function(){
      $.ajax({
        url: "test.htm",
        cache: false,
        success: function(html){
          $("#results").append(html);
        }
      });
    });
    </script>
    </head>
    <body>
    <div id="results">
    
    </div>
    </body>
    </html>
    Or even more simply:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
    <script type="text/javascript">
    $(function(){
      $("#results").load("test.htm");
    });
    </script>
    </head>
    <body>
    <div id="results">
    
    </div>
    </body>
    </html>
    Last edited by jscheuer1; 01-20-2009 at 05:43 PM. Reason: add simplified example
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Jan 2009
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I tried this and other variations but couldn't get that to work.
    Maybe it's just me.
    Did you find out anything more about this piece of code?
    ..................................................................................
    $.ajax({
    url: "test.htm",
    cache: false,
    success: function(html){
    $("#results").append(html);
    }
    });
    });
    ................................................

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I'm not sure what you are asking at this point. Both of my demo pages are working examples. The code in your most recent post will not work unless there is an element with the id 'results' which has been parsed by the browser before it runs. It also requires a page named 'test.htm' to be in the same folder as the page using the code.

    Perhaps a key here is the use in both of my examples of the containing function:

    Code:
    $(function(){
      ajax code goes here
    });
    This is shorthand for the jQuery document ready function, which works like onload, giving the browser the chance to parse the 'results' division before attempting to populate it.

    For more on the $.ajax method itself, see:

    http://docs.jquery.com/Ajax/jQuery.ajax
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #7
    Join Date
    Jan 2009
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks for replying to my call for help, It might just be my browser.
    I have read all the documentation it's probably just me
    Thanks. - Gary

  8. #8
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    For a working demo see:

    http://home.comcast.net/~jscheuer1/s..._ajax/ajax.htm

    It might be your server. If you want more help:

    Please post a link to the page on your site that contains the problematic code so we can check it out.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  9. #9
    Join Date
    Jan 2009
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post ps: It's a remote page

    This is still troubling me, i had left it alone but now i'm back.
    I can't figure out how to replace this page refreshing <iframe> with ajax &/or jQ.
    Your help would be much appreciated.

  10. #10
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    AJAX will not fetch remote pages (I assume you mean from another domain, I do). You can use iframe, but only to display the page itself within an iframe on your page. And that assumes that this remote page has no 'frame busting' code on it. You cannot interact with a remote page in an iframe to say - get its content for import, or even its dimensions for resizing the iframe.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

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