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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:55:33+00:00 2026-06-09T08:55:33+00:00

Edit: I thought about a possible solution, but I made another question as it

  • 0

Edit: I thought about a possible solution, but I made another question as it is very specific: see AJAX proxy with PHP, is it possible?


A couple of times I’ve encountered this problem…

I create sites that have a certain degree of modularity. So, it is possible that there are “components” (think of a rough CMS) which carry their own PHP code, CSS, and JavaScript, all dynamically included. Think about a structure like:

{siteroot}/component/datagrid/datagrid.php
{siteroot}/component/datagrid/js/datagrid.js
{siteroot}/component/datagrid/css/datagrid.css
{siteroot}/component/datagrid/ajax/getsomedata.php

Now, the question is: for JavaScript files, and expecially AJAX calls, how do I make them context-aware with the URLs?
For example, if in datagrid.js I want to call siteroot/component/datagrid/ajax/getsomedata.php with AJAX I should write (with JQuery):

$("#ajax").load("siteroot/component/datagrid/ajax/getsomedata.php");

First problem: siteroot changes on different installations. I’ve managed that by including a general

var codeBase = <? echo json_encode(Config::$siteRoot); ?>

with PHP on every page, from a Config file that can be easily edited for every installation, so I can do with whatever JavaScript something like:

$("#ajax").load(codeBase + "/component/Datagrid/ajax/getsomedata.php");

What do you think of this approach?


Second problem: but I have PHP functions that return to me also the components folder, or the folder of other components. It would be nice to make the whole URL dynamic. This would account also for changes in the structure of the component if I want.
The only solution I’ve found is to use a .js.php dynamic Javascript. This is very unelegant, and I have to include all the framework in the JavaScript file, like:

<?php
include "../../libs/framework.php"; // get my functions...
$myUrl = Config::$siteRoot . Framework::getComponentAjaxDir("datagrid") . "/getsomedata.php";
?>
$("#ajax").load(<?=json_encode($myUrl)?>);

Another side effect is that I have to know exactly the include the path for framework.php… I don’t want this so hard-codedin my “.js.php” file.
Any smart solutions about that?

  • 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-09T08:55:34+00:00Added an answer on June 9, 2026 at 8:55 am

    As nobody answered in a suitable way, I answer to myself to provide a solution I’ve found out that can be useful.
    The key to my solution is simple:

    1. I create an AJAX proxy at a fixed location in my site structure, so I can use codeBase to reference the proxy from JavaScript
    2. I call this proxy with two parameters: plugin and action, which identify a) the plugin folder in which the “real” ajax is and b) the ajax file to use, along with the other params:

      $(“#…”).load( codeBase + “/main/ajax.php?plugin=Datagrid&action=gettable&otherparams”…)

    3. In ajax.php I sanitize the parameters, and use plugin and action to obtain the “real” ajax file:

      {serverRoot}/components/{plugin}/ajax/{action}.php

    Then i simply include that file in ajax.php

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT 07/14 As Bill Burgess mentionned in a comment of his answer, this question
EDIT: See my answer below--> I am wanting to have a view that when
Edit (updated question) I have a simple C program: // it is not important
EDIT: iam using ajax to load text in my content that is why onload
EDIT: Simple version of the question: I want to create server variables in the
I have written a Matlab GUI for my C program. I thought about using
This is a follow up to a previous question that I had before about
This is similar to a previous question , but the answers there don't satisfy
I ask this question expecting the answer to be 'not possible', as I have
I'm beginning to work on mailing-list software we use internally (EDIT: though we send

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.