Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

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

3 Answers 3

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>');
?>
share|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

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.

share|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
add comment
up vote 0 down vote accepted

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

Problem solved though & some good suggestions on here.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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