在 http 页面上使用 https 的 Ajax [英] Ajax using https on an http page

查看:39
本文介绍了在 http 页面上使用 https 的 Ajax的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站使用http和https协议;它不影响内容.我的站点使用 jQuery ajax 调用,它也填充了页面上的某些区域.

My site uses http and https protocol; it doesn't affect the content. My site uses jQuery ajax calls, which fills some areas on the page, too.

现在,我想通过 https 进行所有 ajax 调用.(请不要问我为什么:))当我在使用 https 协议的页面上时,ajax 请求正在工作.当我在使用 http 协议的页面上时,我收到一个 javascript 错误:访问受限 URI 被拒绝

Now, I would like to do all ajax calls over https. (please dont ask me why :)) When I am on a page with https protocol, ajax requests are working. When I'm on a page with http protocol, I get a javascript error: Access to restricted URI denied

我知道这是一个跨域问题(实际上是一个跨协议问题),我知道我应该在ajax调用中使用与当前页面相同的协议.

I know that this is a cross domain problem (in fact, it's a cross protocol problem), and I know that I should use the same protocol in ajax calls as on the current page.

不过,我希望所有 ajax 调用都是 https,并在通过 http 提供的页面上调用它们.是否有任何解决方法可以实现这一点(一些 json/代理解决方案?),还是根本不可能?

Still, I want to all ajax calls to be https, and call them on a page that was served over http. Is there any workaround to achieve this (some json/proxy solution?), or is it simply impossible?

推荐答案

从服务器添加 Access-Control-Allow-Origin 标头

Add the Access-Control-Allow-Origin header from the server

Access-Control-Allow-Origin: https://www.mysite.com

http://en.wikipedia.org/wiki/Cross-Origin_Resource_Sharing

这篇关于在 http 页面上使用 https 的 Ajax的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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