我有一个应用程序通过 Ajax 进行通信以使用来自另一台服务器的一些安静服务的问题。
问题似乎只出现在 IE 上,当消费应用程序位于具有 ssl 的服务器中时,我的意思是当我从其他盒子的同一台服务器上使用相同的服务时,一切正常。
我在具有 SSL 的服务器(https://api.restbla/..)上有 Restful 服务,我必须从其他服务器(有或没有 ssl 证书)使用这些服务
使用 Internet Explorer 进行测试,我得到了结果:
- 如果我使用本地作品中的服务
- 如果我从同一个盒子(托管restful的地方)使用服务
- 如果我在没有 ssl 的情况下使用来自另一台服务器的服务
- 但是当我在 https 上使用服务器上的服务时,在 IE 上不起作用。
之前的所有测试都使用 Chrome 和 FF
这是我用来进行 ajax 调用的 javascript
function load(_url, _callback, _params, _type, _htmlMethod, _onStartFunction, _onFinishFunction) {
var xhr;
if (isFunction(_onStartFunction)) { _onStartFunction(); }
ieVersion = getInternetExplorerVersion();
if (typeof XMLHttpRequest !== 'undefined') {
console.log("XMLHttpRequest");
xhr = new XMLHttpRequest();
}else {
if (ieVersion > 7){
console.log("XDomainRequest");
xhr = new XDomainRequest();
}else{
var versions = [ "MSXML2.XmlHttp.5.0", "MSXML2.XmlHttp.4.0", "MSXML2.XmlHttp.3.0", "MSXML2.XmlHttp.2.0", "Microsoft.XmlHttp" ];
for ( var i = 0, len = versions.length; i < len; i++) {
try {
console.log("ActiveXObject: " + versions[i]);
xhr = new ActiveXObject(versions[i]);
break;
} catch (e) { /* attempt next one*/ }
}
}
}
xhr.onreadystatechange = ensureReadiness;
if (_type == JSON_TYPE) {
contentType = "application/json";
}else{
contentType = 'text/plain';
}
function ensureReadiness() {
if (xhr.readyState < 4) { return; }
if (xhr.status !== 200) {
showServiceDown();
if (isFunction(_onFinishFunction)) { _onFinishFunction();}
return;
}
if (xhr.readyState === 4) {
if (isFunction(_onFinishFunction)) {_onFinishFunction(); }
var responseText = "";
responseText = xhr.responseText;
if (_type == JSON_TYPE) {
_callback(responseText);
} else if (_type = HTML_TYPE) {
var replaced = responseText.replace(/\\/g, '///');
_callback(replaced);
} else { _callback(responseText); }
}
}
if ((_htmlMethod == undefined) || (_htmlMethod == null) || (_htmlMethod == "")) {
_htmlMethod = METHOD_POST;
}
xhr.open(_htmlMethod, _url, true);
xhr.withCredentials = true;
xhr.setRequestHeader("Content-type", contentType);
_params = (_params != undefined) ? _params : null;
xhr.send(_params);
}
我不能为这个项目使用任何 javascript 框架。
证书是公司内部使用的,仅供内部使用,因此任何浏览器验证邮件都会失败,我不知道这是否与问题有关。
我希望有人对这个问题有一些解决方案。
非常感谢您的时间。