Note that there are some explanatory texts on larger screens.

plurals
  1. PORewriting Root Directory Path "/" for Javascript
    primarykey
    data
    text
    <p>We can modify the document root directory path for PHP using </p> <pre><code>$_SERVER['DOCUMENT_ROOT'] = "to/some/new/directory"; //Now the "/" which represent the ^(above) path </code></pre> <p>in .htaccess we have</p> <pre><code>RewriteBase "/to/some/new/directory" </code></pre> <p>Now, I need to modify the root directory path to use in javascript. How to do it?</p> <p>Currently, I am declaring a variable containing static path to the my personalized root directory and using it as</p> <pre><code>var root = "../to/new/path"; document.location = root+"/somepage.php"; </code></pre> <h1>Scenario</h1> <p>I think i should tell a little bit about the scenario, for you guys to catch my idea</p> <p>Default Web Root Directory</p> <pre><code>http_docs/ </code></pre> <p>inside it contain a main folder</p> <pre><code>http_docs/application &lt;-- contains the actual application http_docs/js &lt;-- contains the script http_docs/index.html </code></pre> <p>Now, the application also contains ajax feature for updating, editing, loading new content, or other resources, which if accessed at "/" will represent at /some/path/i/called not /application/some/path/i/called,</p> <p>To come around this problem I can define a static variable like</p> <pre><code>var root = "application/"; </code></pre> <p>and use it somewhere like</p> <pre><code>$.post(....., function(data) { $(body).append("&lt;img src='"+root+"resources/img1.jpg"); }); </code></pre> <p>But for a single use, defining the path as static, might not be a big deal, but, when the application grows, and certain modification would cause me to change all the paths i give in the js part. I thought, it would be sensible, just like, I do it in PHP, using <code>&lt;img src="/resources/img1.jpg" /&gt;</code></p> <p>I tried my best to explain this question, if still is not understandable, please community, lets help them understand. I welcome you to edit my question. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload