Ajax using https on an http page(在 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 http 页面上使用 https 的 Ajax
基础教程推荐
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
