问题描述
我在这个假期工作,发现我的代码无法在 HTTPS 上运行.我的 LOCALDEV 是 HTTP,我们的生产服务器是 HTTPS.
I worked this holiday to find out my code wont work on HTTPS. My LOCALDEV is HTTP and our production server is HTTPS.
出于某种原因,当我在本地拥有 JS 时,YUI 会出去获取 JS.
For some reason YUI is going out to get JS, when I have it locally.
我在服务器上.......
I have it on the server...........
最后是我的代码:
YUI().use('autocomplete', 'autocomplete-filters', 'autocomplete-highlighters', function (Y) {
var notes = [
"Dr Follow Up Complete Notes",
"Fax Document Notes",
"Event Notes",
"Email Information Notes",
"Corresponding Document Notes",
"Return Call Notes",
"Admit Notes",
"Discharge Notes",
"Other Notes",
"Excellent Resource Notes",
"Good Resource Notes",
"Neutral Resource Notes",
"Poor Resource Notes",
"Unacceptable Resource Notes",
];
var inputNode = Y.one('#name');
inputNode.plug(Y.Plugin.AutoComplete, {
resultFilters : 'phraseMatch',
resultHighlighter: 'phraseMatch',
source : notes,
minQueryLength : 0
});
inputNode.ac.get('boundingBox').setStyle('zIndex', 50);
inputNode.on('focus', function () {
inputNode.ac.sendRequest('');
})
====================================================================================
==================================================================================
我的构建中没有那个目录.
I don't have that directory in my build.
推荐答案
TLDR:尝试设置 base
调用 YUI 中的配置属性.
TLDR: try setting the base
config property in your call to YUI.
我没有使用过 YUI,但一般来说,来自 HTTPS 站点的请求应该总是访问其他 HTTPS 站点(否则您会看到不安全的内容警告,或者您发现请求会被阻止).这就是问题所在.
I haven't used YUI, but generally speaking, requests from a HTTPS site should always hit other HTTPS sites (otherwise you'll see insecure content warnings, or requests get blocked as you've discovered). So that's the problem.
我可以想到两个选项来解决这个问题:
You have 2 options I can think of to fix this:
配置 YUI 以从 HTTPS 站点请求.Google 的 AjaxAPI 确实托管了它并且 确实支持 SSL,但它似乎已从 Google 的托管库列表.一位 YUI 开发人员于 2011 年在 YUI 论坛中发帖表明 Google 停止托管新版本的 YUI,原因是Google 的 CDN 不支持组合处理.所以这不是一个真正的选择,有些人认为通过 HTTPS 加载的外部脚本很糟糕.
Configure YUI to request from a HTTPS site. Google's AjaxAPIs did have it hosted and did support SSL, but it appears to have been removed from Google's list of hosted libraries. A post in the YUI forums by a YUI developer in 2011 indicates Google stopped hosting new versions of YUI due to Google's CDN not supporting combo handling. So that's not really an option, and some people are of the opinion that external scripts loaded over HTTPS are bad anyway.
配置 YUI 以从本地服务器加载内容.这要求您的 javascript 不仅在本地存在,而且还将由您的服务器在特定 URL 上提供.除了使您的初始 script
标记指向您本地托管的 YUI 脚本之外,它看起来像 配置客户端加载是通过设置 base
调用 YUI 中的配置属性(或 comboBase
如果您使用的是组合加载器 - 但这意味着您必须设置您自己的 YUI 组合加载器).
Configure YUI to load the content from your local server. This requires that your javascript is not only locally present but will also be served by your server at a particular URL. Aside from making your initial script
tag point to your locally hosted YUI script, it looks like configuring the client side loading is done by setting the base
config property in your call to YUI (or comboBase
if you are using a combo loader - but that would mean you'd have to set up your own YUI combo loader).
例如,如果您的 YUI 库位于 https://mydomain.com/static/js/yui_3.6.0/yui/build/
(并且您的页面位于,请说 https://mydomain.com/sample/page
),那么您可以执行以下操作:
For example, if your YUI lib is available at https://mydomain.com/static/js/yui_3.6.0/yui/build/
(and your page is at, say https://mydomain.com/sample/page
), then you might do the following:
<script src="https://mydomain.com/static/js/3.6.0/yui/build/yui-min.js"></script>
然后在您的 javascript 文件中:
And then in your javascript files:
YUI({
base: 'static/js/yui_3.6.0/yui/build/'
}).use('node', 'event', function(Y) {
...
})
(或可能 base: '/static/js/yui_3.6.0/yui/build/'
; 我没有方便测试的服务器 - 请报告哪个有效,如果任何!)
(or possibly base: '/static/js/yui_3.6.0/yui/build/'
; I haven't got a server handy to test on - please report back which worked, if any!)
这篇关于YUI 3 将前往 yui.yahooapis.com 获取代码.我是 HTTPS 并且内容被阻止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!