“混合内容被阻止”在HTTPS页面中运行HTTP AJAX操作时 [英] "Mixed content blocked" when running an HTTP AJAX operation in an HTTPS page

查看:1473
本文介绍了“混合内容被阻止”在HTTPS页面中运行HTTP AJAX操作时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单,我正在通过GET(因为它需要这种方式)提交给crm(ViciDial)。我可以成功提交表单,但是如果我这样做的话,crm中的处理文件只会回显成功文本,就是这样。



我想显示的不是该文本我的网站上有一个感谢页面,所以我决定使用AJAX提交表单并将其重定向到我需要的页面,但是我在浏览器中发现了这个错误:


混合内容: https://page.com 上的网页为通过HTTPS加载,
但请求不安全的XMLHttpRequest端点
' http://XX.XXX.XX.XXX/vicidial/non_agent_api.php?queries=query=data
此请求已被阻止;内容必须通过HTTPS提供。


这是我的AJAX脚本:

 < script> 
SubmitFormClickToCall = function(){

jQuery.ajax({
url:http://XX.XXX.XX.XX/vicidial/non_agent_api.php,
data:jQuery(#form-click-to-call)。serialize(),
类型:GET,
processData:false,
contentType:false,
success:function(data){
window.location.href =https://www.example.com/thank-you;
}
});
}
< / script>

只要在网址中设置https就行不通,有什么方法可以提交数据通过GET并将用户重定向到我的谢谢页面?



======================= =====



这里的问题是混合内容,这意味着我通过HTTPS加载了一个页面,并试图通过AJAX访问HTTP中的API。但浏览器不会允许我们这样做。



因此,如果您无法将API设置为HTTPS(这是我的情况),我们仍然可以采用其他方式来解决此问题。



主要问题不是混合内容问题,而是我想将数据提交给API并将用户重定向到一个奇特的感谢页面。我没有使用AJAX,而是使用一个接收数据的PHP文件将它使用curl发送到API(因为服务器端没有混合内容问题),并将我的快乐用户重定向到一个奇特的感谢页面。如果您使用HTTPS在浏览器中加载页面,浏览器将拒绝通过HTTP加载任何资源。正如您尝试过的那样,将API网址更改为使用HTTPS而不是HTTP通常可以解决此问题。但是,您的API不得允许HTTPS连接。因此,您必须在主页上强制使用HTTP或请求允许HTTPS连接。



请注意:如果您转到API网址,而不是尝试使用AJAX加载该请求,该请求仍然有效。这是因为浏览器没有从受保护的页面中加载资源,而是加载了不安全的页面,并且它正在接受该页面。但为了使它通过AJAX可用,协议应该匹配。


I've a form which I'm submitting (through GET as it is required this way) to a crm (ViciDial). I can successfully submit the form however if I do that the processing file at crm will just echo a success text and that's it.

Instead of that text, I want to display a thank-you page on my website, so I decided to use AJAX to submit the form and redirect it to the page I need, however I'm getting this error on my browser:

Mixed Content: The page at 'https://page.com' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://XX.XXX.XX.XXX/vicidial/non_agent_api.php?queries=query=data'. This request has been blocked; the content must be served over HTTPS.

This is my AJAX script:

    <script>
    SubmitFormClickToCall = function(){

        jQuery.ajax({
            url: "http://XX.XXX.XX.XX/vicidial/non_agent_api.php",
            data : jQuery("#form-click-to-call").serialize(),
            type : "GET",
            processData: false,
            contentType: false,
            success: function(data){
                window.location.href = "https://www.example.com/thank-you";
            }
        });
    }
    </script>

Just setting https in the URL won't work, is there any way in which I can submit the data via GET and redirect the user to my thankyou page?

============================

Problem here was mixed content, this means that I loaded a page through HTTPS and was trying to hit via AJAX an API that was in HTTP. But the browser wont allow us to just do that.

So if you can't set the API to be HTTPS (this was my case) we can still approach this in a different way.

The Main Problem was not the mixed content issue it was that I wanted to submit data to an API and redirect the users to a fancy thank you page. Instead of using AJAX, i made a php file that receives the data sends it using curl to the API (as this is being done server side there is no mixed content issue) and redirects my happy user to a fancy thank you page.

解决方案

If you load a page in your browser using HTTPS, the browser will refuse to load any resources over HTTP. As you've tried, changing the API URL to have HTTPS instead of HTTP typically resolves this issue. However, your API must not allow for HTTPS connections. Because of this, you must either force HTTP on the main page or request that they allow HTTPS connections.

Note on this: The request will still work if you go to the API URL instead of attempting to load it with AJAX. This is because the browser is not loading a resource from within a secured page, instead it's loading an insecure page and it's accepting that. In order for it to be available through AJAX, though, the protocols should match.

这篇关于“混合内容被阻止”在HTTPS页面中运行HTTP AJAX操作时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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