SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: ajax includes

  1. #1
    SitePoint Zealot silverviper's Avatar
    Join Date
    May 2005
    Location
    Norway
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ajax includes

    Hi

    I'm having some trouble with ajax includes

    the ajax include script (index.php)

    PHP Code:
    <script type="text/javascript">

    /***********************************************
    * Ajax Includes script-  Dynamic Drive DHTML code library (www.dynamicdrive.com)
    * This notice MUST stay intact for legal use
    * Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
    ***********************************************/

    //To include a page, invoke ajaxinclude("afile.htm") in the BODY of page
    //Included file MUST be from the same domain as the page displaying it.

    var rootdomain="http://"+window.location.hostname
    var preview

    function ajaxinclude(url) {
        var 
    page_request false
        
    if (window.XMLHttpRequest// if Mozilla, Safari etc
        
    page_request = new XMLHttpRequest()
        else if (
    window.ActiveXObject){ // if IE
        
    try {
        
    page_request = new ActiveXObject("Msxml2.XMLHTTP")
        } 
        catch (
    e){
        try{
        
    page_request = new ActiveXObject("Microsoft.XMLHTTP")
        }
        catch (
    e){}
        }
        }
        else
        return 
    false
        page_request
    .open('GET'urlfalse//get page synchronously 
        
    page_request.send(null)
        
    writecontent(page_request)
    }

    function 
    writecontent(page_request){
        if (
    window.location.href.indexOf("http")==-|| page_request.status==200)
        
    document.getElementById("mycontent").innerHTML=page_request.responseText;
        
    //document.write(page_request.responseText)
    }
    </script> 
    my links: (index.php)

    <a href="#" onclick="ajaxinclude('includes/include.php?id=main');"> //main.php
    <a href="#" onclick="ajaxinclude('includes/include.php?id=about');"> //about.php

    so far it works like a charm, however, if i add this link to main.php
    <a href="#" onclick="ajaxinclude('includes/include.php?id=about');"> it wont
    include the about.php

    any clues why not?

    thx

    Chris

  2. #2
    SitePoint Zealot silverviper's Avatar
    Join Date
    May 2005
    Location
    Norway
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    got it working, just a stupid mistake

    I forgot i had a preview content function

    PHP Code:
    function preview(prev) {
        
    document.getElementById("inf").innerHTML=prev;

    and a <a href="#" onmousedown="preview('Loading About, please wait...');" onclick="ajaxinclude('includes/include.php?id=main');">
    on the links, witch pretty much wipes out the links in the <div id="inf"> tag

    Chris

  3. #3
    SitePoint Zealot silverviper's Avatar
    Join Date
    May 2005
    Location
    Norway
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi,

    I just got another problem with ajax inludes.

    It seems that all javascript in files included with ajax fails to run

    example

    [about.php]
    This is a
    <script language="javascript">document.write("test")</script>
    [/about.php]

    that file should print out "this is a test", i only get "This is a"

    why?

    thx

    Chris


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
  •