title: jQuery: determine the [server's] Document Root
body: <p>in PHP you can get the document root by: <code>$_SERVER['DOCUMENT_ROOT']</code>. Ej:</p>
  
  <p><strong>PHP</strong></p>
  
  <pre><code>&lt;?php
  $root = $_SERVER['DOCUMENT_ROOT'];
  $path = '/example/directory/';
  $file = 'some-file.html';
  
  include( $root . $path . $file );
  
  ...etc
  ?&gt;
  </code></pre>
  
  <p>How can I get the value of <code>$_SERVER['DOCUMENT_ROOT']</code> in jQuery/JavaScript?</p>
  
  <p><strong>jQuery</strong></p>
  
  <pre><code>//Example:
  var root = ????;
  var path = 'example/directory/';
  var file = 'some-file.txt';
  
  $("#example").load( root + path + file );
  </code></pre>
  
  <p>Notes: Whenever I work on directories, on an HTML page, the "BASE" directory becomes the directory of the current file. Ej, <code>www.ejample.com/documents/examples/this-ex.html</code>. If I just call <code>$("#example").load( path + file )</code> the request would be <code>documents/examples/ + example/directory</code>. Like I said, it's not a question about server-side stuff. Is about getting a correct (and automatic) directory position</p>