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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:57:59+00:00 2026-06-13T08:57:59+00:00

Possible Duplicate: How AJAX is done in github source browse? At the moment I

  • 0

Possible Duplicate:
How AJAX is done in github source browse?

At the moment I have a div and the following code on a link:

<a href="#" onclick="$('div#content').load('Admin/users.php');" id="admin-panel-icon"></a>

Basically, that just loads the file users.php in to the div content that is on the index.php page. In the URL bar, a # just gets added after index.php taken from the href=”#”.

So I have made it now so that the link looks like the following:

<a href="#AdminUsers" onclick="$('div#content').load('Admin/users.php');" id="admin-panel-icon">

But now there is the problem of bookmarking and page refreshing. How would I go about making it so that when a user visits index.php#AdminUsers it loads the users.php file contents in to the div #Contents?

I imagine there is maybe a better solution to what I’m doing. I mean ideally I would like people to be able to visit /Admin/users.php and not have any hash tags but I’m not sure how I’d go about doing this whilst at the same time only loading the users.php content?

  • 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-06-13T08:58:01+00:00Added an answer on June 13, 2026 at 8:58 am

    You’ll need to check onLoad ($(document).ready()) if your URL has hashes.
    If it does, jQuery should load the specified content. But you’ll have to link somehow ‘#AdminUsers’ to ‘Admin/users.php’. I’d recomend using hidden inputs for that.

    First of all, create a function to load ajax content (instead of doing that directly on links)

    function loadContent(page){
        $('div#content').load(page);
    }
    

    and in your link:

    <a href="#AdminUsers" onclick="loadContent('Admin/users.php');" id="admin-panel-icon" ></a>
    

    and somewhere, in every page:

    <input type="hidden" name="AdminUsers" id="AdminUsers" value="Admin/users.php" />
    

    Note that I’ve put a custom hash (AdminUsers) in the href. So, when the user clicks on it, it’ll put the desired hash on the url.

    And finally, the function to check the hash on load:

    $(document).ready(function(){
        if(window.location.hash){
            var hash = window.location.hash;
            $target = $('#'+hash.slice(1));
            if ($target.length) {//found the hidden input field with your URL
                loadContent($target.val());
            }
        }
    });
    

    If you want to display the full page when directly accessed, do: (in PHP):

    <?php if(empty($_SERVER['HTTP_X_REQUESTED_WITH']) ||
     strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest'): //not ajax -> display header ?>
    <div id="header">
       <!-- header content -->
    </div>
    <?php endif; ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: jquery ajax return: undefined I have written the following code to check
Possible Duplicate: return AJAX callback return I have made a JQuery code using AJAX,
Possible Duplicate: Wait until all jquery ajax request are done? I have an array
Possible Duplicate: jQuery: Return data after ajax call success I have the following function
Possible Duplicate: jQuery AJAX submit form I have a form on a page A,
Possible Duplicate: How to: Back button support “Ajax” I have a ASP.NET MVC implementation
Possible Duplicate: jQuery won't parse my JSON from AJAX query So I have parsed
Possible Duplicate: jquery/ajax load new content when available i have a table named news
Possible Duplicate: Kill Ajax requests using JavaScript using jQuery Here is the simple code
Possible Duplicate: Rails - AJAX to for new/create action I have a timeline that

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.