【问题标题】:Jquery ajax call from https to http从 https 到 http 的 Jquery ajax 调用
【发布时间】:2014-12-09 08:28:58
【问题描述】:

我使用 https 协议在 IIS 中部署了我的网站。它适用于 http,但 ajax jquery 请求使用 https 失败。 (我只是调用了一个返回 json 数据的 http web api)

NetworkError:无法在“XMLHttpRequest”上执行“发送”:无法加载“http://.....”

您在使用 https 进行部署时遇到过同样的错误吗?

请记住,下面的代码在使用 HTTP 部署时运行良好,但切换到 HTTPS 时会出现错误部分

var dataGetter = {
    authenticate: function (username, password) {
        var getTokenUrl = "http://xxx";
        var getTokenParams = { "username": username, "password": password }
        var result = false;        
        $.ajax({
            type: "GET",
            url: getTokenUrl,
            data: getTokenParams,
            contentType: "text/plain",
            dataType: 'json',
            crossDomain: true,
            cache: false,
            success: function (result) {
                  // do something here
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert(errorThrown);
                alert(XMLHttpRequest.responseText);
            },
            async: false
        });

        return result;
    }

【问题讨论】:

  • 跨域请求?
  • @axel.michel 我已经配置了它并设置为 true 请记住,当我使用 http 协议部署它时它仍然可以正常工作
  • @Jai 我已经启用了记住,当我使用 http 协议部署它时它仍然可以正常工作
  • @BacClunky 我仍然建议阅读一下:ajax-cross-origin.com/how.html

标签: jquery ajax http https


【解决方案1】:

你不能。它是浏览器中的基本隐式安全性,不允许您从 https 页面调用不安全的链接 (http)。

例如:谷歌浏览器会给你以下错误:

混合内容:“”处的页面是通过 HTTPS 加载的,但请求了不安全的资源“”。此请求已被阻止;内容必须通过 HTTPS 提供。

【讨论】:

    猜你喜欢
    • 2011-06-29
    • 2014-05-09
    • 1970-01-01
    • 2016-10-17
    • 1970-01-01
    • 2012-10-28
    • 2014-07-26
    • 2014-09-15
    • 1970-01-01
    相关资源
    最近更新 更多