当使用 https 而不是 http 时,JSONP 请求失败
我有一个 API 客户端,它使用 JQuery 发出 JSONP 请求.一切正常当此 API 客户端不使用 SSL 但使用 SSL 时失败.
I have an API client which makes a JSONP request using JQuery. Everything works fine when this API client's not using SSL however fails when the SSL is used.
例如,我有一个 URL http://apiclient.com 并且我正在从该域发出以下 JSONP 请求:
For example I have a URL http://apiclient.com and I am making following JSONP request from this domain:
$.ajax({
url: url,
dataType: "jsonp",
contentType: "application/json; charset=utf-8",
success: function(data)
{
$.each(data.services, function(index, service) {
processService(service);
});
}
});
我看到向 url 中指定的 API 主机发出的适当请求和 success 中的回调函数被正确调用,并正确调用了传递给它的格式正确的数据.
I see an appropriate request made to API host specified in the url and callback function in success is properly called with properly formatted data passed onto it.
但是,当我将 API 客户端的上述 URL 更改为 https://apiclient.com 时,在 API 主机上没有观察到请求.我在日志的任何一边都没有看到错误.
However when I change above URL of the API client to https://apiclient.com, no request is observed at API host. I see no errors in either side of the logs.
注意:唯一的区别是 API 客户端的 http 和 https.
Note: only difference is http to https on API client side.
使用 https 域时是否需要以不同方式处理 JSONP 请求?
Do you need to handle JSONP request differently when using https domain?
谢谢.
此问题仅在 Chrome 中观察到.它适用于 Firefox 和 Safari.但是,我在 FireFox 上收到了一个快速警告,询问我将要从以下位置发出未加密的请求加密站点.我允许它并且再也没有看到警告.
This issue is only observed with Chrome. It works with Firefox and Safari. However I got a quick warning on FireFox asking I am about to make unencrypted request from encrypted site. I allowed it and never saw the warning again.
找到了解决方案.问题是 JQuery 和其他资源是从非安全站点导入的.解决方案是从https引用.
Found a solution. Problem was that JQuery and other resources were imported from non-secure sites. Solution was to reference from https.