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

Thread: Dynamic Ajax Content & Link in DIV

  1. #1
    Join Date
    Jul 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Dynamic Ajax Content & Link in DIV

    Dynamic Ajax Content
    http://www.dynamicdrive.com/dynamici...jaxcontent.htm

    Including my php-Files from server works really fine, but what kind of link do I have to put in my external php-File to load from there a new external page into my origina div?

  2. #2
    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

    Did you try the obvious? Something like:

    HTML Code:
    <a href="javascript:ajaxpage('test.htm', 'contentarea');">test</a>
    - John
    ________________________

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

  3. #3
    Join Date
    Jul 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    yes, I did.
    I get the javascript error, that the function "ajaxpage" is not defined.
    When looking at the page-source, I don't see the html-page-source of my external loaded page, so that I cannot say, if the javascript-File is included...

  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

    That means that you have to put the script on or linked it to the head of the page. When using includes, it is generally best to do this on the page(s) that include other content, rather than on the page(s) that get included.
    - John
    ________________________

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

  5. #5
    Join Date
    Jul 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I did include the .js-File in my index.php (on that page, I include external pages), but it doesn't work. ´
    When including the javascript-code in the page, I include, it doesn't work too... maybe anybody has an working example...

  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

    What do you mean by:

    I did include the .js-File in my index.php
    If you literally mean include, this often does not work. The script needs to be on (hard coded on the page) or linked to the head of the page, ex of linking to the page:

    Code:
    <script type="text/javascript" src="path/scriptfilename.js">
    
    place script credit here
    
    </script>
    - John
    ________________________

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

  7. #7
    Join Date
    Jul 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I already have "included" the .js-File as you described in your post, but it does not work.
    Could you please post an working example with a simple javscript-action (like an alert)? I tried for hours, but no success...

  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

    Quote Originally Posted by pbundschuh
    I already have "included" the .js-File as you described in your post, but it does not work.
    Could you please post an working example with a simple javscript-action (like an alert)? I tried for hours, but no success...
    Ah, now the true problem is becoming apparent. Dynamic Ajax content (the ajaxpage function) is not for loading scripts. It is for loading HTML content.

    If you are using the loadobjs function to load a script, generally that may (under certain circumstances) be able to execute a command in the script the first time the script is attached to the document.

    The way that ajaxpage and loadobjs are to be used with scripts is that ajaxpage loads the markup and loadobjs loads the script. It is then user activated triggers in the content that will set the script in motion.

    However, if either the script or the markup are extensive or take awhile to append to the page, there can be lag time before both are fully functional together. And, if the script must initialize content loaded by ajaxpage, the content must be there before the initialization is run and the initialization must be run by a separate function that first determines (usually through polling) if the content has successfully loaded.
    - John
    ________________________

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

  9. #9
    Join Date
    Jul 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    ok, back to my origin problem; is there really no possibility to change the content of the div with a link out of the external loaded page?

  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

    Well, I don't know if this is a PHP specific issue or not but, I just downloaded the demo archive from the demo page. I then opened it up and tried it out. Of course, it worked as expected. Next I took its external2.htm and added a link that loads the external.htm to it so that external2.htm now looks like so (addition red):

    Code:
    <img border="0" src="ajaxfiles/ferrari.jpg">
    <h3 id="cartitle" style="border-bottom: 1px solid #C0C0C0; margin-bottom: -5px">Ferrari Testarossa</h3>
    <p>The Ferrari Testarossa is an V12 mid-engined sports car made by Ferrari. 
      The name, which means &quot;red head&quot;, comes from the red painted cylinder heads on 
      the flat-12 engine. The engine was technically a 180° V engine since it shared 
      flat-plane crankshaft pins with opposing cylinders. Output was 390 hp (291 
      kW), and the car won many comparison tests and admirers - it was featured on 
      the cover of Road &amp; Track magazine nine times in just five years. Almost 
      10,000 Testarossas, 512TRs, and 512Ms were produced, making this one of the 
      most common Ferrari models despite its high price and exotic design. [<a href="http://en.wikipedia.org/wiki/Ferrari_Testarossa#Testarossa">source</a>]<br>
    <a href="javascript:ajaxpage('ajaxfiles/external.htm', 'rightcolumn');">Porsche Page</a>
    I can click on that added link and it will load external.htm into the 'rightcolumn'. The only tricky part (if this is not a PHP specific problem) is that the path to external.htm in the ajaxpage call has to be either absolute (probably safest/easiest for a live installation) or relative to the 'top page' (as in my example), not to the 'loaded page'.
    - 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
  •