2013-08-28 65 views
1

我只是在本地.html文件这一行:为什么我无法从本地文件加载jQuery?

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

作为标准加载谷歌的jQuery的。

但是GET请求,只不过没有......铬控制台只是显示小红x其中:

GET file://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js 

:(什么错

+0

你错过了':'在'http://' – Reigel

+0

离开http并使用'// ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js'并不罕见。看到这篇文章:http://stackoverflow.com/questions/15692601/links-without-http-like-code-jquery-com-etc – dcaswell

回答

2

这是一个错误的网址,它在http://中缺少冒号(:)。

这很可能来自使用速记src="//ajax.googleapis.com...。浏览器会在//的前面加上正确的方案http:https:,但是由于您在本地访问它,因此预先配置了file:方案 - 该方案预计资源位于本地驱动器上。

对于本地开发人员,使用具有指定方案的完全限定URL或使用本地网络服务器,以便您可以使用httphttps方案访问文档。

1

它需要:

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

如上所述,您可以使用:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> 
+0

....哦。我复制了他们的回购链接....认为这是对的。不知道他们为什么忽略了'http' ... https://developers.google.com/speed/libraries/devguide#jquery – Aerovistae

+2

@Aerovistae:他们使用的是协议相关的URL。 – SLaks

+0

@Aovovistae - 如果您离开协议,那么它将适用于HTTP或HTTPS。 –

相关问题