问题描述
我尝试执行ajax,我的代码写在https网站上请求非https,但资源被Chrome阻止。
I try to do ajax, my code written on a https site it request to non https, but the resources were blocked by Chrome.
$.ajax({
url : "http://example.com/non-https",
..
..
以前在早期版本中我没有这个问题。我的ajax请求也必须以https为目标吗?或者有更好的方法来保存这个问题?
Previously in earlier version I don't have this issue. Must my ajax request target a https too? Or there is a better way to save that problem?
推荐答案
只需更改你的url变量中 http://
到 //
,所以当页面加载http时,ajax请求将使用http协议,如果加载https,浏览器将ajax请求协议设置为https。即,您的代码应如下所示:
Just change the http://
in your url variable to //
, so when the page is loaded with http, the ajax request would use the http protocol, if loaded with https, the ajax request protocol would be set by the browser to https. i.e, your code should look like:
$.ajax({
url : "//example.com/non-https",
..
..
这篇关于此请求已被阻止;内容必须通过HTTPS提供的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!