1

I'm running CentOS 5.5 64bit - Trying to load a jquery plugin from a PHP file.

The line I am using is...

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

...This does not work. However, If I change the line to...

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" ></script> 

...it works no problem. I can access the file through the browser, ie http://myserver.com/tools/jquery.js. Now I'd usually just the use the google hosting, but I've got some other Jquery plugins that I want to load locally. Any ideas why this isn't working? Cheers

EDIT:

To make it more confusing - I also tried...

<script type="text/javascript" src="http://myserver.com/tools/jquery.js"></script> 

...but no luck.

I have also done chmod 755 on the jquery files. Giving read and execute permissions to everyone (-rwxr-xr-x).

1
  • Could you paste the php file? (minus the body) Commented Jun 22, 2011 at 10:48

3 Answers 3

1

Try:

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

EXAMPLE:

<?php printf ('<html>'); printf ('<head>'); printf ('<script type="text/javascript" src="./tools/jquery.js"></script>'); printf ('<script type="text/javascript">'); printf ('$(document).ready(function(){'); printf (' $("button").click(function(){'); printf (' $(this).hide();'); printf (' });'); printf ('});'); printf ('</script>'); printf ('</head>'); printf ('<body>'); printf ('<button>Click me</button>'); printf ('HEY'); printf ('</body>'); printf ('</html>'); ?> 
6
  • Hi sorry, I should have explained - The lines I am using are how you see them, plain HTML, I have not opened the PHP tag yet. i.e. I am not printf-ing or echo-ing the lines. I tried the line above but it still doesn't work. Commented Jun 22, 2011 at 11:36
  • Do this src="./tools/jquery.js" put a "." in from of the first "/". Are you running a PHP enabled version of Apache? Commented Jun 22, 2011 at 11:41
  • Tried that - Thats the same as at the top of your answer: <script type="text/javascript" src="./tools/jquery.js"></script> Commented Jun 22, 2011 at 11:47
  • Maybe this is an htaccess issue? Commented Jun 22, 2011 at 13:11
  • Is there a htaccess file in the tools directory? Commented Jun 22, 2011 at 13:18
0

I assume you're using Apache, the error_log file should show a 404 for jquery.js and indicate what path your HTML makes it seem to be at.

I'd also use Firefox with 'Live HTTP headers' to see your requests/responses, to see if it's being asked for properly.

To be pedantic, jquery isn't a plugin as most people thing about plugins, but that's not a big deal.

1
  • Nothing in the error_log. If I view the source, I can click the links to the js files and view them no problem - The path / location appears to be fine. I've just looked at 'Live HTTP Headers' and they seem fine. Any other ideas? Thanks for the help Commented Jun 23, 2011 at 10:05
0

Reinstalled apache and it started to work. Wierd...

Problem solved though & some good suggestions on here.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.