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 933557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:51:11+00:00 2026-05-15T20:51:11+00:00

Now here is my situation: I’m making a CMS. When links are clicked, i

  • 0

Now here is my situation: I’m making a CMS. When links are clicked, i would like the pages to load dynamically using Ajax. The problem in the links!

The only way to change the address in the address bar real-time is to use anchor tags. But PHP doesn’t get the anchor tags, thus I can’t load page content on site load using PHP.
And if i were to load the pages using a query string, the query string couldn’t be updated in the address bar at the click of a link, since that would reload the page.

I suppose Javascript could check the address, save the anchor tag in a cookie and reload the page, but I’d rather not have to go to such lengths.

Does anyone know a solution to this problem?

  • 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-15T20:51:12+00:00Added an answer on May 15, 2026 at 8:51 pm

    There was a similar question not so long ago, and I came up with the following solution.

    Your urls should point to real pages in order to get it work in for js disabled users. The click handlers should handle ajax requests. Hash should contain the url, and a part like &ajax to indicate the type of the request.

    If the request is from ajax simply send the content. If it is not, wrap the content into header and footer to respond with a full site.

    Urls should work with linking to ajax generated hashes and using them as links. The whole idea is basically mimics the kind of behavior you can see on facebook.

    Javascript

    // click handler for ajax links
    function goToWithAjax(hash) {
      hash = hash.href ? hash.getAttribute("href", 2) : hash;
      ajax( hash, function( response ) {
        document.getElementById("content").innerHTML = response;
      });
      hash = ("#!/" + hash).replace("//","/");
      window.location.hash = hash;
      return false;
    }
    

    .htaccess

    auto_prepend_file = "prepend.php"  
    auto_append_file  = "append.php"  
    

    prepend

    $url   = $_SERVER['REQUEST_URI'];
    $parts = explode('#!', $url);
    $hash  = isset($parts[1]) ? $parts[1] : false;
    
    // redirect if there is a hash part
    if ($hash) {
      header("Location: $hash");
    }
    
    // find out if it's an ajax request
    $ajax = strstr($url, "&ajax");
    
    // we need header if it's not ajax
    if (!$ajax) {
      get_header();
    }
    

    append

    // we need footer if it's not ajax
    if (!$ajax) {
      get_footer();
    }
    

    get_header()

    function get_header() {
    
    echo <<< END
    <html>
    <head></head>
    <body>
    <div id="page">
      <div id="header">
        <div id="logo"></div>
        <ul id="nav">menu...</ul>
      </div>
      <div id="content">
    END;
    
    }
    

    get_footer()

    function get_footer() {
    
    echo <<< END
      </div> <!-- end of #content --->
      <div id="footer">(c) me</footer>
    </div> <!-- end of #page --->
    </body>
    </html>
    END;
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I asked the question here and now i would like to reverse this procedure
I'm using CodeIgniter 2.1.2 and here's my situation right now. I have a model
Here is the situation : If I am in page-1 now I am clicking
So here is what the method looks like now: POST person/personId/edit https://api.example.com/*key*/person/*personId*/edit?FName=Blah I want
Here's how it looks like right now: my screenshot Is there a way for
I have a situation here there are two models User,Posts Now I want to
Here's the situation, I created 6 pages,each of which has some text fields.I stored
I'm in a somehow tough situation here. I need to load data from multiple
Here's my situation, I have 2 pages, one for selecting a value and one
Here's the situation... Right now, there's a site that's being hosted (DNS is already

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.