从https到http的Jquery ajax调用 [英] Jquery ajax call from https to http

查看:530
本文介绍了从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.

这篇关于从https到http的Jquery ajax调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆