从HTTPS页面强制将AJAX调用设为HTTPS [英] Forcing AJAX call to be HTTPS from HTTPS Page

查看:362
本文介绍了从HTTPS页面强制将AJAX调用设为HTTPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前正在从HTTPS jsp进行AJAX调用,以从另一个jsp页面中调用数据.但是,我们遇到了混合内容问题:

Currently making an AJAX call from a HTTPS jsp to call in data from another jsp page. We are however getting a Mixed content issue:

混合内容:" https://etc/"上的页面是通过HTTPS加载的,但是 请求了不安全的XMLHttpRequest端点 " http://etc/path/to/other/page.jsp ".该请求已被阻止; 内容必须通过HTTPS提供.

Mixed Content: The page at 'https://etc/' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://etc/path/to/other/page.jsp'. This request has been blocked; the content must be served over HTTPS.

如何强制AJAX调用通过HTTPS进行调用?

How do you force an AJAX call to call over HTTPS?

AJAX调用如下所示:

The AJAX call looks like the following:

var url = "/path/to/other/page.jsp";

$.ajax({                                                            
    type: "POST",
    url: url,
    data: {data: data},
    dataType: "html",
    timeout: 4000, 
    success: function(html) {
        /* Code on Success */
        }
    },
    error: function(request, status, error) {
         /* Code on Failure
    }   
});

我可以理解我是否尝试从HTTPS到HTTP进行呼叫,但我不想这么做.我想强制使用HTTPS来全部调用JSP,因此可以避免出现混合内容"问题.

I could understand if I was trying to make a call from HTTPS to HTTP, but I don't want to. I want to force this to call the JSP using HTTPS is all, so I can avoid the Mixed Content issue.

先谢谢您!

/*编辑*/

有趣的是,我在变量URL中输入了绝对路径:

Interestingly I put in the variable URL an absolute path:

var url = "https://etc/path/to/other/page.jsp";

我也遇到了同样的问题.是什么迫使该AJAX调用成为HTTP?

And I got the same issue. Something is forcing this AJAX call to be HTTP?

推荐答案

尝试使用其他扩展名或带有.htaccess的类似文件夹等.

Try use another extension or use like folder with .htaccess etc. like this

var url = "https://etc/path/to/other/page/";

这篇关于从HTTPS页面强制将AJAX调用设为HTTPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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