1
<html>
<head><title>test</title>

  <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js">
  </script>
  <!-- ERROR IS HERE the jquery is not being loaded -->

  <script type="text/javascript" src="js/jquery.prettyPhoto.js">
  </script>
  <link rel="stylesheet" href="css/prettyPhoto.css" type="text/css" 
      media="screen" charset="utf-8" />
</head>
<body>
  <a title="Despicable Me" rel="prettyPhoto[movies]" 
    href="http://trailers.apple.com/mymovie.mov?width=640&height=360">
    <img src="images/thumbnails/quicktime-logo.gif" alt="Despicable Me" 
    width="50" />
  </a>
  <a title="Despicable Me" rel="prettyPhoto[movies]" 
    href="ai.mov?width=640&height=360">
    <img src="images/thumbnails/quicktime-logo.gif" 
      alt="Despicable Me" width="50" />
  </a>
  <script type="text/javascript" charset="utf-8">
    $(document).ready(function(){
      $("a[rel^='prettyPhoto']").prettyPhoto();
    });
  </script>
</body>
</html>

When I load this html in firefox, the error console returns an error:

jQuery is not defined. 

The html file, js file, and the css file are all in the same folder. What am I doing wrong?

Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
Ali Alzahrani
  • 529
  • 1
  • 6
  • 29

3 Answers3

6

I think you run this in local. (Note: not mean localhost, mean you opened the local html file)

If you run in local, then //ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js means file:///ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js

So you need to specify the http://

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>

But once you upload your page to the server, it's ok with just //, and this is best practice.

xdazz
  • 158,678
  • 38
  • 247
  • 274
  • @wisdom I don't mean localhost, I mean you run the html as local file. – xdazz Oct 15 '12 at 11:36
  • @xdazz My apologies, thought you were just suggesting adding `http:` like everyone else. After your edit I see what you are saying, accessing it outside of a web server will be using the `file:` protocol, which isn't suitable for fetching the script. – GenericJon Oct 15 '12 at 11:37
  • @GenericJon No problem, I didn't organize my answer well and lead the misunderstanding. – xdazz Oct 15 '12 at 11:40
5

Sorry Last Answer was wrong

Try downloading jquery from google and use it from local server like

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

AND

If all files are under same directory then when you are appending js/ in front of jquery.prettyPhoto.js and also css/ they should be like

<html>
<head>
<title>test</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript" src="jquery.prettyPhoto.js"></script>
<link rel="stylesheet" href="prettyPhoto.css" type="text/css" media="screen"  charset="utf-8" />
</head>
<body>
<a title="Despicable Me" rel="prettyPhoto[movies]" href="http://trailers.apple.com/movies/universal/despicableme/despicableme-tlr1_r640s.mov?width=640&height=360"><img     src="quicktime-logo.gif" alt="Despicable Me" width="50" /></a>
<a title="Despicable Me" rel="prettyPhoto[movies]" href="ai.mov?width=640&height=360"><img src="quicktime-logo.gif" alt="Despicable Me" width="50" /> </a>

<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
  $("a[rel^='prettyPhoto']").prettyPhoto();
});
</script>
</body>
</html>
simply-put
  • 1,068
  • 1
  • 11
  • 20
0

use

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>

to get the JQuery file from the google server

MaVRoSCy
  • 17,747
  • 15
  • 82
  • 125