JnBrymn
JnBrymn

Reputation: 25383

Loading jquery from google doesn't work (for me)

Ah the wretched noob I am, the following html document doesn't alert anyone of my cry for help. Anyone know why?

<html>
<head>
<script type="text/javascript"
 src="//ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript">
  $(document).ready(function() {
    alert('Somebody please help me.');
  });
</script>
</head>
<body>
</body>
</html>

Upvotes: 0

Views: 3414

Answers (6)

Ryan
Ryan

Reputation: 28247

This works for me:

<html>
<head>
<script type="text/javascript"
 src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript">
  $(document).ready(function() {
    alert('Somebody please help me.');
  });
</script>
</head>
<body>
</body>
</html>

Just fixed the src in the script tag.

Edit: Actually, the original syntax would work fine if you load the page in a non-local context. Leaving out the protocol implies that the 'current' protocol would be used depending on whether resources are loaded over http or https. Loading it locally implies that the script is loaded from file:///ajax.googleapis.com/...., which obviously won't resolve to anything. See here for more information. Thanks to @PetrolMan for pointing to the HTML 5 boiler plate site.

Upvotes: 6

PetrolMan
PetrolMan

Reputation: 381

That same syntax is used in the HTML5 Boilerplate:

<!-- Grab Google CDN's jQuery, with a protocol relative URL; fall back to local if necessary -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.js"></script>
<script>window.jQuery || document.write("<script src='js/libs/jquery-1.5.2.min.js'>\x3C/script>")</script>

Upvotes: 3

Ritesh Mengji
Ritesh Mengji

Reputation: 6190

Possible values for the Src Attribute are

•An absolute URL - points to another web site (like src="http://www.example.com/example.js") •A relative URL - points to a file within a web site (like src="/scripts/example.js")

So you should have your URL as http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js

Upvotes: 0

Tejs
Tejs

Reputation: 41256

The source is jacked up. Use

src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"

Upvotes: 0

Darin Dimitrov
Darin Dimitrov

Reputation: 1039438

You are missing an http: in front of the url in the src attribute of the <script> tag:

<html>
<head>
<script type="text/javascript"
 src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript">
  $(document).ready(function() {
    alert('Somebody please help me.');
  });
</script>
</head>
<body>
</body>
</html>

Upvotes: 0

Jason McCreary
Jason McCreary

Reputation: 73031

It's

http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js

not

//ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js

Upvotes: 0

Related Questions