Joe Slater
Joe Slater

Reputation: 2473

Jquery not working from Google CND

I just started creating a html file and wanted to use jquery. When I use the jquery from my local machine like this, it works fine.

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

But when I try to use this, it does not work

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

I am not able to use any jquery functions when I load the script like this.

What am I doing wrong here?

EDIT: Btw, my html file is on the local machine in drive C:/

Upvotes: 14

Views: 7670

Answers (2)

Jack
Jack

Reputation: 8941

Your url is incomplete. I believe they leave off the http to show that you can use either http or https, because if you're on a server you don't need it. You only need to add it in if you're running off your file system.

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

Upvotes: 20

cspotcode
cspotcode

Reputation: 1892

Since the HTML file is on your local machine, I'm guessing you're viewing it using the file:// protocol. Since you've omitted the protocol from your <script> tag's src attribute, it will also use the file:// protocol and fail.

I'd suggest hosting the site using a simple webserver running on localhost. There are a few other oddities when using file:// that might cause you trouble.

Upvotes: 14

Related Questions