0

Just having a hard time here, hope it's really to solve... Here it goes:

While trying to include jQUery, in a script, it will only load it if the file is located in the base directory (working with localhost, my file is called jquery.js):

<script type="text/javascript" src="jquery.js" ></script>

But when I try to use the same file put in a subfolder, say "js/jquery.js" then it won't recognize it no matter how many different name variants I use:

<script type="text/javascript" src="/js/jquery.js" ></script>
<script type="text/javascript" src="js/jquery.js" ></script>
<script type="text/javascript" src="http://localhost/js/jquery.js" ></script>
<script type="text/javascript" src="http://localhost/js/jquery.js" ></script>

In addition, I tried to get the base directory using "echo $_SERVER['DOCUMENT_ROOT']."";" to add the full path letter by letter to no avail. THe result I got was '/var/www', tried these lines but didn work either:

<script type="text/javascript" src="var/www/js/jquery.js" ></script>
<script type="text/javascript" src="/var/www/js/jquery.js" ></script>

What could be going on here? Weird thing is that images are loaded with no problem, for

example: scr="IMG/imagie.gif"

Any thoughts on this?

Bart Kiers
  • 166,582
  • 36
  • 299
  • 288

1 Answers1

0

It sounds to me like you're using an .htaccess file or some other mechanism that mangles URLs that include directories. Are you using a framework like CodeIgniter or something? Do you have an .htaccess file in the base directory on the filesystem (you'll have to do an ls -a to see it if you do)? Do you have access to the Apache configuration file for that virtual host?

Edit: User determined that root cause was a folder permissions issue.

King Skippus
  • 3,801
  • 1
  • 24
  • 24
  • Hi King, so far nothing like CodeIgniter or anything else. The kinda give you the whole scenario: Ubuntu 12.04 running apache. My javascript works perfectly (as long as files are strictly in base-path) as well as my php5 server. As far as files is concerned, only have an index.file (the one that calls the jquery.js file) and some subfolders... Weird thing is, as I wrote before, that images are loaded from subfolders with no problem whatsoever, but .js files are not... – user1494526 Jul 01 '12 at 17:54
  • Did you do an ls -a in your base directory on the server filesystem? If so, do you have an .htaccess file? Also, what happens if you try to access the file directly in your browser as http://localhost/js/jquery.js? – King Skippus Jul 01 '12 at 17:55
  • King, you definitley opened my eyes, hehehehe... It was all a matter of folder permission, I just noticed that when trying to open js/jquery,js, THANKS! :) – user1494526 Jul 01 '12 at 18:05
  • Wish I could take credit, but what I thought was the issue turned out not to be the issue. Folder permissions would definitely do it, you have to make sure your web server (probably the user www-data, or something similar) has read access to the directory it's stored in. Did accessing it directly in the browser throw an error that pointed to the root cause? – King Skippus Jul 01 '12 at 18:08
  • Yes it did, very straight-forward: "YOU DO NOT HAVE PERMISSION TO ACCESS THIS FILE". I however differ from you giving you all the credit provided you gave me the way to the root of the problem. THANKS! and feel free to answer and close this question (I cannot do it for 7 more hours as I'm a new user here!) – user1494526 Jul 01 '12 at 18:12