jQuery的AJAX在HTTPS - 资源加载失败 [英] jQuery AJAX on HTTPS - Resource failed to load
问题描述
我有自己的API,在 HTTP(S)://www.api.domain.com
(HTTPS上没有安装的RapidSSL)
I have own API at http(s)://www.api.domain.com
(on HTTPS there is RapidSSL installed).
如果我通过浏览器acccess该网址我得到
If I acccess that URL via browser I get
{"error":{"code":404,"message":"Invalid API version."}}
这是很好的。
which is fine.
如果我访问 https://www.api.domain.com/v1/auth
我收到
{错误:{code:404,消息:缺少授权头}}
这也行(签署该API适用于SSL OK)。
which is also OK (sign that API works OK on SSL).
我有jQuery的AJAX调用来自其他域的API。如果我做不使用SSL调用( http://www.api.domain.com/v1/auth
)一切工作正常(我要送授权头和所有其他必要的东西),我得到的回应。如果我尝试进入同样的事情,但是用SSL( https://www.api.domain.com/v1/auth
)我得到选项https://www.api.domain.com/v1/auth~~V资源无法加载
。
I have jQuery AJAX call to that API from other domain. If I make a call without SSL (http://www.api.domain.com/v1/auth
) everything is working OK (I'm sending authorization headers and all other necessary stuff) and I'm getting responses. If I try to access to the same thing but with SSL (https://www.api.domain.com/v1/auth
) I get OPTIONS https://www.api.domain.com/v1/auth Resource failed to load
.
此外, CORS 的工作。在PHP端我有
Also, CORS is working. On PHP side I have
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: Authorization, x-domain-accesskey, X-Requested-With');
exit;
}
所以它的工作,但只是没有SSL。在铬我看到一个选项请求,然后点击 GET / POST / 我要求什么。它工作得很好。
so it's working, but only without SSL. In chrome I see one OPTIONS request and then GET/POST/whatever I requested. It's working just fine.
但是,当我试图继续前进HTTPS,
But when I try to move on HTTPS,
资源无法加载
在网络选项卡,我只有这个(不知道为什么第一幅图像上显示选项,但在细节上的发布)
On Network tab I have only this (not sure why on the first image is showing OPTIONS, but on the details POST)
然后就...停止?在jQuery的停止线
and then just...stops? In jQuery it stops on line
xhr.send( ( s.hasContent && s.data ) || null );
$ AJAX
是正常的(没有跨域:真正的
,的dataType :JSONP
或别的东西)
$.ajax
is normal (don't have crossDomain: true
, dataType: jsonp
or something else).
想法?
推荐答案
使页面您选择发送的渲染HTTPS和它应该很好地工作适合你。https的Ajax请求
make the page youre sending the https ajax request from render in https and it should work fine for you.
这篇关于jQuery的AJAX在HTTPS - 资源加载失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!