简单的 jQuery 代码可以正常工作,直到通过 https:// 加载站点
我有一段简单的 jQuery 代码,用于提交表单并隐藏/显示一些屏幕信息。 测试时它工作正常,直到通过 https:// 加载,它在 IE7 中崩溃。 它似乎完全崩溃了,所有脚本都没有任何效果。 我还收到 IE 警告“某些元素不安全”。
有谁有发生这种情况的经验吗? 或者更好的是,一个解决方案! 我必须通过 https 加载该页面作为信用卡付款页面。
I have a simple peice of jQuery code that submits a form and hides/shows some on screen information. It works fine when tested, until loaded via https:// upon which it breaks in IE7. It appears to break totally, with none of the script having any effect. I also get the IE warning that "some elements are insecure".
Does anyone have any experience of this happening? Or even better, a solution! I have to load the page via https as its a credit card payment page.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
前面的三个答案都提到了安全的“https”页面试图包含来自“http”路径的脚本或其他资源(样式表、图像等)的问题......
我想添加到这些内容,并注意,如果您可能会遇到这样的情况:相同的页面可以通过 http 或 https 加载,那么您可以创建“无协议”URL——该协议将被假定为与当前页面相同。 请注意,这仅在访问不同域上的资源时才需要(并且仅在这些不同的域同时支持 http 和 https 时才有效),因为显然如果您要访问同一域上的资源,则不需要以 http 开头: // 根本...
例如,这三个资源中的每一个都将采用 http 或 https,具体取决于当前页面的访问方式:
The three previous answers all mention the problem of a secured "https" page trying to include scripts or other resources (stylesheets, images, etc) from an "http" path...
I would like to add to these, and note that if you have a situation where the same pages could be loaded via either http or https, then you can create "protocol-less" URLs---the protocol will be assumed to be the same as the current page. Note this is only needed for accessing resources on different domains (and will only work if those different domains support both http and https), because obviously if you're accessing resources on the same domain, you don't need to start with http:// at all...
For example, each of these three resources would assume either http or https depending on how the current page was accessed:
如果您通过
https://
提供页面,则每个资源链接也应使用https://
。 密切注意,提防,小心If you serve a page via
https://
then every resource link should also usehttps://
. Look out for感谢您的所有意见。 该问题最终被追踪到 Thickbox.js 中提到的一个图像。
因为它有一个 http:// (不是 https://) url,所以导致了错误消息。 弹出的安全消息对加载不安全内容有“是”或“否”选项,单击“是”则告诉浏览器完全停止加载任何 jQuery。
这确实是一个棘手的问题,所以我想我会回答自己,希望它可以帮助其他遇到同样问题的人。
Thank you for all your input. The problem was eventually tracked down to an image mentioned in Thickbox.js.
Because that had a http:// (not https://) url it was causing the error message. The security message that pops up has a yes or no to loading insecure content, and clicking yes was telling the browser to stop loading any jQuery at all.
A tricky one indeed so I thought I would answer myself in the hope it might help someone else with the same problem.
如果客户端使用 HTTPS 请求页面,则页面应通过 HTTPS 链接到所有媒体(图像、脚本、样式表)。
如果客户端使用 HTTP 请求页面,那么您应该在响应中发送此 HTML 片段:
如果客户端使用 HTTPS 请求页面,那么您应该在响应中发送此 HTML 片段:
不同之处在于,当客户端使用 HTTPS 请求页面,服务器会发回一个以
https://
开头的 jquery 脚本链接。If the client used HTTPS to request the page, then the page should link to all media (images, scripts, stylesheets) via HTTPS.
If the client used HTTP to request the page, then you should send this HTML fragment within your response:
If the client used HTTPS to request the page, then you should send this HTML fragment within your response:
The difference is that, when the client requests the page with HTTPS, the server sends back a link to the jquery script that starts with
https://
.如果您使用 jquery,您也可能会看到类似的行为
code.jquery.com
例如:
code.jquery.com 没有有效的 SSL。
这可能会导致其他脚本无法正常工作。
使用 google cdn 代替或从您自己的服务器加载 jquery
希望有帮助
You may also see a similar behaviour if you are using jquery from
code.jquery.com
eg:
code.jquery.com does not have a valid SSL.
This may cause other scripts to not work correctly.
use the google cdn instead or load the jquery from your own server
Hope it helps
我使用 IE 11 作为浏览器。
解决办法:不要使用兼容模式。 工具->兼容性视图设置。
症状:
程序在http模式下运行良好。
浏览器报告了一行错误,声称需要标识符。
浏览器不允许对 jquery 库文件进行调试。 文件没有
显示在要调试的文件列表中,可以设置断点
如果通过开发人员的错误消息访问该文件
控制台日志,但断点已禁用。
浏览器清楚地显示文件已成功加载。
使用其他浏览器时没有出现错误。
提示:我将测试程序精简为加载 jquery 库文件和显示固定文本的单个 div,因此我自己的代码不会出错。 这极大地简化了可能出现问题的列表。
I was using IE 11 as the browser.
Solution: Do not use compatibility mode. Tools->Compatibility View Settings.
Symptoms:
Program had worked fine in http mode.
Browser reported an error at a line, claiming an identifier was expected.
Browser would not allow debugging on the jquery library file. File did not
show up in the list of files to debug, break points could be set on
the file if accessed via the error message in the developer's
console log, but the breakpoints were disabled.
Browser clearly showed the file was loaded successfully.
No error appeared when using a different browser.
Hint: I stripped the test program down to loading the jquery library file and a single div that displayed fixed text, so there wasn't any of my own code to go wrong. That greatly simplified the list of what could be wrong.