gpt4 book ai didi

javascript - AngularJS 模板无法通过 HTTPS 加载

转载 作者:行者123 更新时间:2023-12-01 03:00:33 25 4
gpt4 key购买 nike

我从 Cloudflare 获得了 SSL,他们直接将其分配给我的域,并自动将所有 http 重定向到 https

话虽如此,我正在努力让我的 Angular 模板通过 https 加载。

错误信息是:

Mixed Content: The page at 'https://mydomain.io/components/index/#/' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://mydomain.io/components/index/header'. This request has been blocked; the content must be served over HTTPS.

这看起来有点简单,但我一直在尝试解决这个问题,但我无法...

这就是我从指令.js 文件加载模板的方式:

app.directive('navHeader', function() {
return {
templateUrl: function() {
var useHTTPS = window.location.href.indexOf('https') > -1;
if (useHTTPS) {
return 'https://mydomain.io/components/index/header.html';
} else {
return 'header.html';
}
}
};
}),

但它显然不起作用......

有什么想法吗?难道是cloudflare的错吗?

最佳答案

这可能是@Cloudflare的原因,

因为您正在尝试访问https而不是http的数据,但问题是服务器是否响应该协议(protocol),因此您需要检查服务器端的重定向,

如果任何请求来自 http 或 https,那么它将始终重定向到 https 服务器。

关于javascript - AngularJS 模板无法通过 HTTPS 加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46453156/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com