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).

link|improve this question
Could you paste the php file? (minus the body) – slotishtype Jun 22 '11 at 10:48
feedback

3 Answers

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>');
?>
link|improve this answer
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. – steve Jun 22 '11 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? – slotishtype Jun 22 '11 at 11:41
Tried that - Thats the same as at the top of your answer: <script type="text/javascript" src="./tools/jquery.js"></script> – steve Jun 22 '11 at 11:47
Maybe this is an htaccess issue? – slotishtype Jun 22 '11 at 13:11
Is there a htaccess file in the tools directory? – slotishtype Jun 22 '11 at 13:18
show 1 more comment
feedback

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.

link|improve this answer
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 – steve Jun 23 '11 at 10:05
feedback
up vote 0 down vote accepted

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

Problem solved though & some good suggestions on here.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.