Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
100
rated 0 times [  105] [ 5]  / answers: 1 / hits: 23276  / 10 Years ago, thu, may 29, 2014, 12:00:00

in PHP you can get the document root by: $_SERVER['DOCUMENT_ROOT']. Ej:



PHP



<?php
$root = $_SERVER['DOCUMENT_ROOT'];
$path = '/example/directory/';
$file = 'some-file.html';

include( $root . $path . $file );

...etc
?>


How can I get the value of $_SERVER['DOCUMENT_ROOT'] in jQuery/JavaScript?



jQuery



//Example:
var root = ????;
var path = 'example/directory/';
var file = 'some-file.txt';

$(#example).load( root + path + file );


Notes: Whenever I work on directories, on an HTML page, the BASE directory becomes the directory of the current file. Ej, www.ejample.com/documents/examples/this-ex.html. If I just call $(#example).load( path + file ) the request would be documents/examples/ + example/directory. Like I said, it's not a question about server-side stuff. Is about getting a correct (and automatic) directory position


More From » php

 Answers
33

Are you looking for document.location.hostname?



var root = document.location.hostname;

$(#example).load( root + path + file );

[#70801] Wednesday, May 28, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
elians

Total Points: 417
Total Questions: 87
Total Answers: 101

Location: Barbados
Member since Sun, Nov 27, 2022
1 Year ago
;