从https到http的Jquery ajax调用

问题描述:

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

I deployed my website in IIS with https protocol. It works fine with http but ajax jquery request is failed with https. (I simply call a http web api which returns json data)

NetworkError:无法在'XMLHttpRequest'上执行'send':无法加载'http://。 ....

NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'http://....."

使用https进行部署时是否遇到了同样的错误?

Did you get the same kind of errors when deploying with https?

请记住以下代码在使用HTTP部署时效果很好,但切换到HTTPS后转到错误部分

Remember that this code below works well when deploy with HTTP, but switch to HTTPS it went to error section

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;
    }

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

You cannot. Its the basic implicit security in browsers which doesn't allow you to call a insecure link (http) from https page.

例如:,Google Chrome将为您提供以下服务错误:

For example:, Google Chrome will give you following error:

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

Mixed Content: The page at '' was loaded over HTTPS, but requested an insecure resource ''. This request has been blocked; the content must be served over HTTPS.