Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6861867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:35:25+00:00 2026-05-27T02:35:25+00:00

http://www.queness.com/post/328/a-simple-ajax-driven-website-with-jqueryphp I’m trying to get the above script to work, but with some changes.

  • 0

http://www.queness.com/post/328/a-simple-ajax-driven-website-with-jqueryphp

I’m trying to get the above script to work, but with some changes. I need the content to load as php includes, and not as an html string. My main problem right now is that i don’t think the code is directing to the right page, thus no new content.

php:

switch($_GET['page'])  {
    case 'code' : $page = include ($_SERVER['DOCUMENT_ROOT'].'mysite/code.php'); break;
    case 'design' : $page = include ($_SERVER['DOCUMENT_ROOT'].'mysite/design.php'); break;
    case 'writing' : $page = include ($_SERVER['DOCUMENT_ROOT'].'mysite/writing.php'); break;

html:

<ul id="menu">
         <li><a title="index" href="#index.php" rel="ajax"><span>home</span></a></li>
         <li><a title="code" href="#code.php" rel="ajax"><span>code</span></a></li>
         <li><a title="design" href="#design.php" rel="ajax"><span>design</span></a></li>
         <li><a title="illustration" href="#illustration.php" rel="ajax"><span>illustration</span></a></li>
         <li><a title="writing" href="#writing.php" rel="ajax"><span>writing</span></a></li>
         <li><a title="links" href="#links.php" rel="ajax"><span>links</span></a></li>
         <li><a title="about" href="#about.php" rel="ajax"><span>about</span></a></li>
        </ul>

javascript:

<script type="text/javascript">

    $(document).ready(function () {

    //Check if url hash value exists (for bookmark)
    $.history.init(pageload);   

    //highlight the selected link
    $('a[href=' + document.location.hash + ']').addClass('selected');

    //Seearch for link with REL set to ajax
    $('a[rel=ajax]').click(function () {

        //grab the full url
        var hash = this.href;

        //remove the # value
        hash = hash.replace(/^.*#/, '');

        //for back button
        $.history.load(hash);   

        //clear the selected class and add the class class to the selected link
        $('a[rel=ajax]').removeClass('selected');
        $(this).addClass('selected');

        //hide the content and show the progress bar
        $('#content').hide();
        $('#loading').show();

        //run the ajax
        getPage();

        //cancel the anchor tag behaviour
        return false;
    }); 
});


function pageload(hash) {
    //if hash value exists, run the ajax
    if (hash) getPage();    
}

function getPage() {

    //generate the parameter for the php script
    var data = 'page=' + document.location.hash.replace(/^.*#/, '');
    $.ajax({
        url: "loader.php",  
        type: "GET",        
        data: data,     
        cache: false,
        success: function (html) {  

            //hide the progress bar
            $('#loading').hide();   

            //add the content retrieved from ajax and put it in the #content div
            $('#content').html(html);

            //display the body with fadeIn transition
            $('#content').fadeIn('slow');       
        }       
    });
}

    </script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:35:26+00:00Added an answer on May 27, 2026 at 2:35 am

    you sure you get the right path?

    case 'code' : $page = include($_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.'mysite/code.php'); break;
    case 'design' : $page = include($_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.'mysite/design.php'); break;
    case 'writing' : $page = include($_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.'mysite/writing.php'); break;
    

    $_SERVER[‘DOCUMENT_ROOT’] in different environments may has trailing slash or not, so be careful when including files from $_SERVER[‘DOCUMENT_ROOT’]

    case 'code' : $page = include ($_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.'mysite/code.php'); break;
    case 'design' : $page = include ($_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.'mysite/design.php'); break;
    case 'writing' : $page = include ($_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.'mysite/writing.php'); break;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

http://www.zignals.com/main/ The above website is a market place for stock brokers strategies, would anybody
I am using some excellent code for a photo slide show from http://www.queness.com/post/1450/jquery-photo-slide-show-with-slick-caption-tutorial-revisited .
I found this tutorial: http://www.queness.com/post/356/create-a-vertical-horizontal-and-diagonal-sliding-content-website-with-jquery And I like the way this site does their
http://www.switchonthecode.com/tutorials/getting-started-with-opengl-es-for-the-iphone From the above link they created tutorial by No Nib File. But i
http://www.leandrovieira.com/projects/jquery/lightbox/ sample so i have get images in while loop here is my code
http://www.myserver.com/exile?Key1=Value1&Key2=Value2 When i get a request in this format to my server, how do
http://www.trafficestimate.com/,http://getclicky.com/,http://technotarget.com/find-out-who-is-visiting-your-site-website-traffic-tools/,http://pmetrics.performancing.com/ The above are sample websites for trimming. I want to extract only the
http://www.flickr.com/photos/fraserspeirs/4329430635/in/set-72157623224262135/ The above is a link basically showing the form fill view of the
http://www.e-fluential.com/offline/ Screen grab: I can't get the div that the blue words blah blah
http://www.dscredstorm.com/getisbninfo.aspx I'm trying to use Amazon's api. I downloaded their example code, which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.