I am trying to include a .js file into a php file. My folder structure looks like this:
root
---js (FOLDER)
------file.js
---blog (FOLDER)
------index.php
------js (FOLDER)
---------blog.js
If I am using this:
<script type="text/javascript" src="../js/blog.js"></script>
it works just fine.
What I can't seem to do is include file.js from under the root's "js" directory. I've tried everything I can think of but I just can't seem to make it work.
I am trying to include a .js file into a php file. My folder structure looks like this:
root
---js (FOLDER)
------file.js
---blog (FOLDER)
------index.php
------js (FOLDER)
---------blog.js
If I am using this:
<script type="text/javascript" src="../js/blog.js"></script>
it works just fine.
What I can't seem to do is include file.js from under the root's "js" directory. I've tried everything I can think of but I just can't seem to make it work.
Share asked Aug 29, 2009 at 4:59 James P. WrightJames P. Wright 9,12923 gold badges82 silver badges144 bronze badges 1- Well this is actually on my localhost right now for testing purposes, which means that the file is actually located at /localhost/php/mysite/js/ I was hoping for a way to be able to just go up two levels and start from there. Is there no way to do that at all? – James P. Wright Commented Sep 1, 2009 at 23:36
3 Answers
Reset to default 4<script type="text/javascript" src="/js/file.js"></script>
would reference the javascript file in the top level js directory
To access the blog, is a user going to www.domain. or www.domain./blog?
If /root/blog is your DOCROOT in your web server, the /root/js directly likely isn't web-accessible. The location you're referencing MUST be accessible to the client's browser.
An easy way to test this is to enter the path to the JS file directly into your browser.
it looks like blog is in a subdirectory of the folder index.php is in. Discard the ../
bit.
<script type="text/javascript" src="js/blog.js"></script>
<script type="text/javascript" src="../js/file.js"></script>