jQuery CDN未在LocalHost上加载 [英] jQuery CDN is not loading on LocalHost
问题描述
我从以下地址加载了jquery cdn:
I have a jquery cdn loading from the following:
<head>
.
.
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
</head>
然后在我的脚本中有我的源代码
then in the body I have my source for my script
<body>
.
.<script src="app.js"></script>
</body>
这一切都在本地,但是当我在浏览器中查看时,我在控制台中不断收到以下错误:
This is all on local, but when I view in browser I keep getting the following errors in console:
GET file://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
Uncaught ReferenceError: $ is not defined
我认为这是说jQuery函数$ ...未定义,因为CDN的GET中有错误,为什么会发生在本地?
I assume this is saying the jQuery function "$..." is undefined because there is an error in GET of the CDN, why would this be happening on local?
推荐答案
您实际上并没有在localhost( http:// localhost
)上运行,而是在本地文件系统上运行( file:/// path / to / whatever.html
)。该协议使用 //
链接复制到 file://ajax.googleapis.com
当然没有'存在。
You aren't actually running on localhost (http://localhost
) but on the local file system (file:///path/to/whatever.html
). The protocol is copied with the //
link to file://ajax.googleapis.com
which of course doesn't exist.
您应该在计算机上设置服务器,以便使用http协议访问实际 localhost。它还有其它好处,因为当页面直接从文件系统加载时,浏览器的其他方面也有所不同。
You should set up a server on your computer so that you'd have an actual localhost accessed with the http protocol. It would have other benefits as well since browsers act a bit differently also in other regards when the page is loaded directly from the file system.
这篇关于jQuery CDN未在LocalHost上加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!