通过 HTTPS 的 Ajax GET 请求 [英] Ajax GET request over HTTPS

查看:38
本文介绍了通过 HTTPS 的 Ajax GET 请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过 HTTPS 发送 ajax GET 请求?

How can I send an ajax GET request over HTTPS?

$.get 抛出这个:

XMLHttpRequest cannot load https://********. Origin null is not allowed by Access-Control-Allow-Origin. 

是否有其他方法或解决方法可以使其正常工作?

Is there another way or some workaround to get this working?

如果我使用 Chrome 导航到 url,我就能得到响应.我看不出为什么它不应该在 ajax 请求上工​​作.

If I navigate to the url with Chrome I'm able to get the response. I see no reason why it shouldn't work work over an ajax request.

推荐答案

如果您当前在 http 中,则无法向 https 页面发出 AJAX 请求,因为同源政策.

You cannot make an AJAX request to an https page if you are currently in http because of the Same Origin Policy.

主机端口方案(协议)必须相同才能使 AJAX 请求工作.

The host, port and scheme (protocol) must be the same in order for the AJAX request to work.

您可以确保原始页面在同一主机和方案上,或者实施 CORS(跨域资源共享) 在目标域上允许此特定请求.

You can either make sure that the originating page is on the same host and scheme or implement CORS (cross-origin resource sharing) on the target domain to permit this particular request.

这篇关于通过 HTTPS 的 Ajax GET 请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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