简体   繁体   English

在HTTPS安全页面上引用jQuery CDN?

[英]Referencing jQuery CDN on a HTTPS secured page?

What's the preferred way of referencing a jQuery library on pages that use https? 在使用https的页面上引用jQuery库的首选方式是什么? We have a checkout masterpage that needs to make use of jQuery UI widget but I keep getting an error: 我们有一个结帐母版页,需要使用jQuery UI小部件,但我不断收到错误消息:

Uncaught TypeError: Object #<Object> has no method 'dialog'

When calling the jQuery dialog. 调用jQuery对话框时。 I've looked in chrome tools and the page is trying to get the library over https but it's location is defined as http in my markup. 我看过chrome工具,该页面正在尝试通过https获取该库,但在我的标记中将其位置定义为http So what I'm asking is, how can i reference these libraries on secured pages? 所以我要问的是,如何在安全页面上引用这些库? Do i reference a local copy within the site itself rather than a CDN? 我是否在站点本身而不是CDN中引用本地副本? Or is there a https version that i can use? 还是有我可以使用的https版本?

Thanks 谢谢

Google and Microsoft CDNs serve jQuery and jQuery UI through HTTPS as well. Google和Microsoft CDN也通过HTTPS提供jQuery和jQuery UI。 Just switch the protocol. 只需切换协议即可。 Eg: 例如:

https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js

You can also just omit the protocol when referencing the external library: 您也可以在引用外部库时忽略协议:

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

This way the script will be loaded using the same protocol as its document. 这样,脚本将使用与其文档相同的协议来加载。

Both serve through HTTPS also, but the best way is to just not use HTTP part at all and use // only. 两者都通过HTTPS服务,但是最好的方法是根本不使用HTTP部分,而仅使用//

Example: 例:

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

By not using any HTTP protocol in your code, it means you need not worry about the conditional logic for whether it is actually needed or not. 通过在代码中不使用任何HTTP协议,这意味着您不必担心是否实际需要使用条件逻辑。 So your shopping pages won't have to be targeted specifically. 因此,您的购物页面无需专门定位。

Hope that helps clear it up. 希望可以帮助清除它。

Thanks. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM