Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript ajax load php into page div

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #40842
    fiefscent
    Member

    I’ve got a small php site where my index.php loads content based on the nav links — so a link “http://mysite.com/?page=contact” will load the contact.php file after the header.php, nav.php, and before the footer.php. Works great.
    Now I want to use jQuery ajax to load the various ‘content’ php files based on the URL as in the sample above. How do I do that? I’ve tried using the tutorial here (https://css-tricks.com/examples/AJAXReplaceSamePart/) but it depends on using nice neat .html extensions for the links.

    #114592
    JohnMotylJr
    Participant

    @fiefscent,

    Have you tried this?

    jQuery’s .get( ) method

    #115074
    fiefscent
    Member

    got it. here’s what i did:

    var toLoad = $(this).attr(‘href’).match(/page=(.*)/)[1]+’.php’;
    function loadContent() {
    $(‘#content’).load(toLoad,”,showNewContent())
    }

    #115077
    Paulie_D
    Member

    Is this solved?

    #122799
    jawmoke
    Member

    I apologize in advance if this is too much to ask. My situation sounds much like the original question. I’ve got a php site with divisions, “header”, “navigation”, “content”, and “footer” in the css and includes in the index.php file for them. My goal is to have a folder with all the content pages which will load into the content division of the index file by clicking on a link in the navigation.php file. This way all I have to do is add a link for a new content page. I’ve read many online articles relating to this but I’m not a coder and they always leave out where the code goes and which variables to change. If I could get some specific example of how to do this, I’d be most appreciative. Here’s a couple of sites I’ve made that I want to change and eliminate the side menu if it’s possible to have enough submenus in the navigation bar to give the content.php more width.
    http://patrioticrevelations.com/
    http://patrioticrevelations.com/gec/

    #122847
    jawmoke
    Member

    I think I found a solution and I think I probably should’ve started a new thread with my question. Please just delete my two posts. FWIW, here’s what I did.

    put the following in the content.php file

    $default = “info/pageone.php”;
    $allowed = array (
    ‘info/pagetwo’,
    ‘info/pagethree’,
    );
    if( isset( $_POST[“P”] ) || isset( $_GET[“P”] ))
    {
    $page = isset($_GET[“P”]) ? $_GET[“P”] : $_POST[“P”];

    if( in_array( trim ( $page ), $allowed ))
    {
    $file = $page . “.php”;
    if( (file_exists( $file )))
    {
    include( $file );
    }
    else
    {
    include( $default );
    }
    }
    else
    {
    include( $default );
    }
    }
    else
    {
    include( $default );
    }
    ?>

    navigation.php has:

    Page One    
    Page Two     
    Page Three    

Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.