cancel
Showing results for 
Search instead for 
Did you mean: 

Correct path for external JavaScript files?

wynnmc
Dabbler
Posts: 15
Registered: ‎03-04-2008

Correct path for external JavaScript files?

A page using jQuery runs on Apache on my computer but doesn't on ccgi.myname.plus.com.
I've done some tests and this
<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Demo</title>
  </head>
  <body>
    <a href="http://jquery.com/">jQuery</a>
    <script src="jquery.js"></script>
    <script src="test1.js"></script>
  </body>
</html>

runs -- even when (all files are) moved into a subdirectory Test1.
This
<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Test 2</title>
  </head>
  <body>
    <a href="http://jquery.com/">jQuery</a>
    <script src="/Test2/js/jquery.js"></script>
    <script> src="/Test2/js/test2.js"</script>
  </body>
</html>

doesn't -- even with the variations for the path to the JavaScript files as
src="js/jquery.js">

which works on my computer as the directory containing test2.html has a js subdirectory containing the two JavaScript files.
Anyone have any ideas?
Chris
2 REPLIES 2
spraxyt
Resting Legend
Posts: 10,063
Thanks: 674
Fixes: 75
Registered: ‎06-04-2007

Re: Correct path for external JavaScript files?

Quote from: wynnmc
This
<!doctype html>
<html>
 <head>
   <meta charset="utf-8">
   <title>Test 2</title>
 </head>
 <body>
   <a href="http://jquery.com/">jQuery</a>
   <script src="/Test2/js/jquery.js"></script>
   <script> src="/Test2/js/test2.js"</script>
 </body>
</html>

doesn't -- even with the variations for the path to the JavaScript files as
src="js/jquery.js">

which works on my computer as the directory containing test2.html has a js subdirectory containing the two JavaScript files.

Your comment suggests to me that you didn't upload the js subdirectory with its JavaScript files to the ccgi server - is that the problem?
Also the second <script> line has a misplaced closing angle bracket (>). it should read
    <script src="/Test2/js/test2.js"></script>

… or was that a typo?
For path definition, either

   <script src="/Test2/js/jquery.js"></script>
   <script src="/Test2/js/test2.js"></script>

or

   <script src="js/jquery.js"></script>
   <script src="js/test2.js"></script>

can be used (assuming Test2 is a directory in your ccgi root directory). I prefer the latter if the application is self-contained since it makes relocating easier.
David
Note: Be careful with capital letters on ccgi, case is significant here.
David
wynnmc
Dabbler
Posts: 15
Registered: ‎03-04-2008

Re: Correct path for external JavaScript files?

Thanks, David  -- I should have been able to see that!
With that correction test2.html now works.
But ... my big HTML/JS still doesn't work, I shall have to crawl over it forwards and then backwards...
Thanks for pointing out my error -- at least, now, I know where to look...
Chris