在某些浏览器上的AjaxPro中的ConnectFailure

Rom*_*Mik 2 .net asp.net cross-platform ajaxpro

在PlayStation 3、4,Xbox360,Xbox One上已重现此问题。所有版本的AjaxPro都存在此问题。

发出Ajax请求(使用AjaxPro)时,服务器返回正确的内容。但是,回调函数中返回的对象是

{
   "error": 
    {
     "Message":"","Type":"ConnectFailure","Status":200},"value":null,
     "request":
     {
       "method":"MethodName",
       "args":
       {
          "Argument1":"1111","Argument2":"2222"
       }
     },
    "context":null,"duration":18
   }
}
Run Code Online (Sandbox Code Playgroud)

Raf*_*eto 5

就我而言,在将AjaxPro与https,TLS 1.2,具有P-256密钥交换的ECDHE_RSA和AES_256_GCM密码(IE11 +,Chrome51 +,Firefox49 +。请在此处查看)一起使用时,也会遇到相同的错误。可以使用带有HMAC-SHA1密码的过时AES_256_CBC正常运行。

问题是服务器响应(我真的不知道为什么)后,XMLHttpRequest.statusText属性为空,而AjaxPro.Request.prototype.doStateChange方法(ajaxpro / core.ashx文件)期望“确定”将响应视为有效:

var res = this.getEmptyRes();
if(this.xmlHttp.status == 200 && this.xmlHttp.statusText == "OK") {
    res = this.createResponse(res);
} else {
    res = this.createResponse(res, true);
    res.error = {Message:this.xmlHttp.statusText,Type:"ConnectFailure",Status:this.xmlHttp.status};
}
Run Code Online (Sandbox Code Playgroud)

我最终决定重写AjaxPro.Request.prototype.doStateChange方法,并在this.xmlHttp.statusText中允许使用空值。

我将此脚本添加到了受影响的页面中:

$(function() {
    if (typeof AjaxPro != 'undefined' && AjaxPro && AjaxPro.Request && AjaxPro.Request.prototype) {
        AjaxPro.Request.prototype.doStateChange = function () {
            this.onStateChanged(this.xmlHttp.readyState, this);
            if (this.xmlHttp.readyState != 4 || !this.isRunning) {
                return;
            }
            this.duration = new Date().getTime() - this.__start;
            if (this.timeoutTimer != null) {
                clearTimeout(this.timeoutTimer);
            }
            var res = this.getEmptyRes();
            if (this.xmlHttp.status == 200 && (this.xmlHttp.statusText == "OK" || !this.xmlHttp.statusText)) {
                res = this.createResponse(res);
            } else {
                res = this.createResponse(res, true);
                res.error = { Message: this.xmlHttp.statusText, Type: "ConnectFailure", Status: this.xmlHttp.status };
            }
            this.endRequest(res);
        };
    }
});
Run Code Online (Sandbox Code Playgroud)


小智 5

在此之前的所有答案的基础上,并供其他寻找此问题的人参考 - 在我们的情况下,我们将其跟踪到 HTTP2 协议(注意 - 我们正在通过 HTTPS 进行测试;我不确定 HTTP 上是否存在问题...)。
- 当我们在浏览器中禁用 HTTP2(或服务器上的 IIS)时,AjaxPro 调用可以正常工作。
- 但是,当使用 HTTP2 时,响应是普通的“200”而不是“200 OK”,并且 AjaxPro 将其解释为失败