jwk811 Posted June 14, 2010 Share Posted June 14, 2010 i use a php function to get "http://www.domain.com" when i go to my javascript file and try to go <?php echo WEB_ROOT; ?> it doesnt work. so is there a way to use php in a javascript if not is there a way to get the website with js? Quote Link to comment https://forums.phpfreaks.com/topic/204776-get-web-root/ Share on other sites More sharing options...
jwk811 Posted June 14, 2010 Author Share Posted June 14, 2010 nevermind it doesnt even work when i put the full url in. its an ajax thing xmlhttp.open("GET","lib/getMessage.php",true); that works for only the front page. but if i go to a different folder it wont work because the url changes. if i put xmlhttp.open("GET","http://www.domain.com/lib/getMessage.php",true); that doesnt work tho! why??? i know this is more ajax/js now but please help Quote Link to comment https://forums.phpfreaks.com/topic/204776-get-web-root/#findComment-1072084 Share on other sites More sharing options...
nblackwood Posted June 14, 2010 Share Posted June 14, 2010 Try this: <?php echo $_SERVER['DOCUMENT_ROOT'];?> Quote Link to comment https://forums.phpfreaks.com/topic/204776-get-web-root/#findComment-1072094 Share on other sites More sharing options...
Alex Posted June 14, 2010 Share Posted June 14, 2010 Your problem could be that you're accessing the web page without the www. and the AJAX request includes the www In that case you should either force www or no www or do something like this: xmlhttp.open("GET","http://" + location.host + "/lib/getMessage.php",true); Quote Link to comment https://forums.phpfreaks.com/topic/204776-get-web-root/#findComment-1072096 Share on other sites More sharing options...
jwk811 Posted June 14, 2010 Author Share Posted June 14, 2010 Your problem could be that you're accessing the web page without the www. and the AJAX request includes the www In that case you should either force www or no www or do something like this: xmlhttp.open("GET","http://" + location.host + "/lib/getMessage.php",true); tytytytytytytytytytytytytytytytytytytytytytytytytytytytytytytytytytytytytytytytytytytytytytytytytytytytyty Quote Link to comment https://forums.phpfreaks.com/topic/204776-get-web-root/#findComment-1072116 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.